如何合并这两个SQL语句?
SELECT SUM(hits01 + hits02 + hits03 + hits04 + hits05 + hits06 + hits07 + hits08 + hits09) AS 'AEROwiz'
FROM tbl_2011
WHERE appName='AEROwiz'
SELECT SUM(hits10 + hits11 + hits12) AS 'AEROwiz'
FROM tbl_2010
WHERE appName='AEROwiz'
两个表中都存在hits10,hits11和hits12。
最佳答案
使用UNION查询-只需在两个查询之间填入“UNION”即可:
SELECT SUM(...) AS AEROWiz
FROM ...
UNION
SELECT SUM(...) AS AEROWiz
FROM ...
更新
将联合包装在另一个查询中:
SELECT SUM(AEROWiz)
FROM (
.... unioned queries here
) AS child