gpt4 book ai didi

php - 我无法构建 SQL 查询(连接)

转载 作者:行者123 更新时间:2023-11-29 14:21:21 25 4
gpt4 key购买 nike

抱歉,标题不明确。

我正在 PHP 上使用 MySQL。

这些是我的表格:

+++++++++++++++++++++++  
|........thread.......|
+++++++++++++++++++++++
|.id.|..title..|..ok..|
+++++++++++++++++++++++
|.45.|.baslik.|...1...|
|.53.|.baslik.|...0...|
|.56.|.baslik.|...1...|
+++++++++++++++++++++++

+++++++++++++++++++++++++++++++++
|............comment............|
+++++++++++++++++++++++++++++++++
|.id.|..text..|.ok.|.thread_id..|
+++++++++++++++++++++++++++++++++
|.1..|.falan..|.0..|....45......|
|.3..|.filan..|.1..|....56......|
+++++++++++++++++++++++++++++++++

我需要的是获取“thread”表的所有已检查(ok=1)行,其行数提供 thread.id = comment.thread_id 和 comment.ok=1 的相等性。

当我使用以下查询时,我会得到选中或未选中的所有评论计数。

select thread.*, count( comment.thread_id ) as countComment from `thread` left join `comment` on thread.id=comment.thread_id where thread.ok='1' group by thread.id

我想要得到的输出必须如下所示。

++++++++++++++++++++++++++++++++++++  
|.id.|.title..|..ok.|.commentCount.|
++++++++++++++++++++++++++++++++++++
|.45.|.baslik.|...1.|......0.......|
|.56.|.baslik.|...1.|......1.......|
++++++++++++++++++++++++++++++++++++

谢谢

最佳答案

试试这个:

LEFT JOINcommentON thread.id = comment.thread_id AND comment.ok = '1'

关于php - 我无法构建 SQL 查询(连接),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11702447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com