日期:2014-05-18  浏览次数:20440 次

SQL 两个结果集拼接起来的问题
SQL code



select Sid,count(*)as Num from t_forums a group by Sid


select b.*,c.SectionName from t_forums b,t_sections c
where b.Id=(select max(id)as Id from t_forums where Sid=c.Id)





接不起来,求高手指导指导

sid num
17
18
20

sid ... SectionName
17
18
20


------解决方案--------------------
SQL code
select a.*,
       b.*,
       c.SectionName 
from t_forums b,t_sections c,
(select Sid,
       count(*)as Num 
from t_forums a 
group by Sid)a
where b.Id=(select max(id)as Id from t_forums where Sid=c.Id)
and a.sid=b.sid