这是三张表
----------------------------peole表------------------------------
id name
1 buman
2 regretwang2000
3 sun
4 sunwang81081
---------------------------note表----------------------------------
id title content writerid
1 shsh shshsh 1
2 sss ssss 1
3 dddd ddddd 2
4 ddd dd 1
---------------------------fabiao表----------------
id fabiaocontent origid
1 sssssssssss 1
2 sss 1
3 wwwwwwwwwww 1
------------------------------------------------------------
要求生成下面这样的查询结果集,要求没有回复的renote对应的值给0即可。
name title renote
-- ----- ----
-- ----- ----
-- ----- ----
select
a.name,
b.title,
renote = (select isnull(count(*),0) from fabiao where origid = b.id)
from
people a,
note b
where
a.id = b.writerid
select B.name as 发帖人
,A.title as 标题
,C.num as 回复数
from note A
join people B on A.writerid=B.id
left join (
select origid,count(1) as num
from answer
group by origid
)C on C.origid=A.id