select a.bbscaptionid,a.bbsnameid,count(b.bbscaptionid) from Bbsinfo a left join Bbscardinfo b on a.bbsnameid = b.bbsnameid group by a.bbscaptionid,a.bbsnameid 这样能查询到全部版块的数据,就是全部的帖子数,版块没有帖子则会自动补0(left join)
但我要查询所有版块的精华帖子数时却查询不出来了,就加了个where条件,就只显示CARDSTATE为3的版块了,闷,试了各种方法都解决不鸟,请高手解决.代码如下 select a.bbscaptionid,a.bbsnameid,count(b.bbscaptionid) from Bbsinfo a left join Bbscardinfo b on a.bbsCaptionId = b.bbsnameid where b.cardstate = 3 group by a.bbscaptionid,a.bbsnameid;