抱歉,标题不明确。
我在 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......|
+++++++++++++++++++++++++++++++++
我需要的是获取“线程”表的所有检查(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.......|
++++++++++++++++++++++++++++++++++++
谢谢,