我想加入两个或多个具有 group by 子句的 select 语句,但它不起作用。
SELECT COUNT(`rank`) AS rank1,sitename
FROM `larrdb_ranking`
INNER JOIN larrdb_site_list USING (sid)
WHERE rank=1
GROUP BY sitename
UNION
SELECT COUNT(`rank`) AS rank2 ,sitename
FROM `larrdb_ranking`
INNER JOIN larrdb_site_list USING (sid)
WHERE rank=2
GROUP BY sitename
我得到的只是第一个语句有效,但第二个语句没有..我没有选择 rank2
更新:
Union All 也不起作用:
SELECT COUNT(`rank`) AS rank1,sitename
FROM `larrydb_ranking`
INNER JOIN larrydb_site_list USING (sid)
WHERE rank=1
GROUP BY sitename
UNION ALL
SELECT COUNT(`rank`) AS rank2 ,sitename
FROM `larrydb_ranking`
INNER JOIN larrydb_site_list USING (sid)
WHERE rank=2
GROUP BY sitename
column..rank2 未显示