我正在尝试根据收到的大多数评论从三个表中获取数据,下面是我的表结构:
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