0

我正在尝试根据收到的大多数评论从三个表中获取数据,下面是我的表结构:

Table A
ID | Follower | Comment | PLACE
-------------------------------
1  | ABC      | TEXT1   | LA
3  | ABC      | TEXT1   | NY
1  | ABC      | TEXT2   | LA
2  | ABC      | TEXT1   | IL
1  | ABC      | TEXT2   | LA

Table B
ID | NAME     | PLACE
-----------------------
1  | Name1    | LA
2  | Name2    | IL
3  | Name3    | NY

Table C
PLACE | COUNTRY 
-----------------------
LA    | US      
IL    | US      
NY    | US  

我想做的是这样的:

    SELECT        
a.PLACE, a.ID, a.NAME, b.PLACE, Count(b.ID) AS CT, c.PLACE, c.COUNTRY
FROM            
TableB AS a INNER JOIN
TableA AS b ON a.ID = b.ID INNER JOIN
TableC AS c ON b.PLACE = c.PLACE
GROUP by b.ID
ORDER BY (CT) DESC
4

1 回答 1

0
select b.ID,b.Name,b.Place,c.COUNTRY,a.MostComments  
from TableB b inner join 
(select ID,count(*) as MostComments from TableA
group by ID) a
on a.ID=b.ID
inner join TableC c
on b.PLACE=c.PLACE
order by a.MostComments Desc
于 2012-10-26T07:38:10.807 回答