一般来说是写存储过程,或者用in关键字和嵌套查询,但是今天发现这样也可以,值得记录:
select *,counts=(select count(*) from work_bbs_reply where pid=a.id) from work_bbs a
select *,counts=(select count(*) from work_bbs_reply where pid=a.id)
,lastreply=(select top 1 reply_content from work_bbs_reply where pid=a.id order by id desc)
from work_bbs a