请教数据库多表查询统计问题!
select talk.talkid,TalkDetail,talktime,usernickname from dbo.talk,dbo.users where talk.userid=users.userid
select talk.talkid,count(talkcomment.tid) as counts from talk inner join talkcomment on talk.talkid = talkcomment.tid group by talk.talkid
select talk.talkid,TalkDetail,talktime,usernickname,t.counts
from dbo.talk
inner join dbo.users on talk.userid=users.userid
inner join (select talkid,count(tid) as counts from talkcomment group by talkid)t
on talk.talkid=t.talkid
--改成LEFT JOIN即可
SELECT a.talkid ,
a.TalkDetail ,
a.talktime ,
b.usernickname,
ISNULL(COUNT(c.tid),0) AS counts
FROM dbo.talk a
INNER JOIN dbo.users b
ON a.userid = b.userid
LEFT JOIN talkcomment c
ON a.talkid = c.tid
GROUP BY a.talkid ,
a.TalkDetail ,
a.talktime ,
b.usernickname