How to combine two sql queries into one

后端 未结 4 1420
南旧
南旧 2021-01-05 15:36

How can I combine these two SQL statements?

SELECT SUM(hits01 + hits02 + hits03 + hits04 + hits05 + hits06 + hits07 + hits08 + hits09) AS \'AEROwiz\'
FROM tb         


        
4条回答
  •  日久生厌
    2021-01-05 16:15

    SELECT  SUM(hits01 + hits02 + hits03 + hits04 + hits05 + hits06 +  
    hits07 + hits08 + hits09) AS 'AEROwiz' 
    FROM    tbl_2011 
    WHERE   appName='AEROwiz' 
    
    UNION ALL
    
    SELECT  SUM(hits10 + hits11 + hits12) AS 'AEROwiz' 
    FROM    tbl_2010 
    WHERE   appName='AEROwiz' 
    

    Use UNION ALL as it will allow duplicates, and UNION will not put duplicates in the query result. With the SUM() aggregate, I'm guessing there's a good chance of duplication summations, so I'd go with UNION ALL for this one.

提交回复
热议问题