有两个表,其中表BBS是帖子的,reply表是回复帖子的。表BBS有字段:id,title,content,createtime,user,count.表reply有字段:id replyuser,replyid,replytime,replycontent. replyid就是帖子BBS表中对应的id。现在要把两个表连接查询,怎么把BBS表中所有字段和表reply 中select count(id) from reply group by replyid所查询的结果结合起来,而且把前面reply表查询的结果赋给BBS字段count....求解语文水平很差,不知道有没有人明白我的意思。
应该是 select count(replyid) from reply group by id
where b.id = t.id and 其他过滤条件
from bbs b left join (Select replyid, count(id) as cnt from reply group by replyid) r on b.id=r.replyid
我现在又有新的疑问了,就是把select count(id) from reply group by replyid得到的数据怎么更新到BBS的count字段中?
update bbs b left join (Select replyid, count(id) as cnt from reply group by replyid) r on b.id=r.replyid
set b.count=r.cnt