【UNION ALL】

select a,b,sum(sm) AS s1, SUM(qm) AS s2 from   
(  
 select 'a' AS a, 'b' AS b, 2 AS sm, 200 AS qm   
UNION ALL  
 select 'a' AS a, 'b' AS b, 2 AS sm, 200 AS qm  
)r  
group by a,b  
ab4400

【UNION】

select a,b,sum(sm) AS s1, SUM(qm) AS s2 from   
(  
 select 'a' AS a, 'b' AS b, 2 AS sm, 200 AS qm   
UNION   
 select 'a' AS a, 'b' AS b, 2 AS sm, 200 AS qm  
)r  
group by a,b 
ab2200

总结:UNION ALL全部列出,UNION会去掉重复的。


丰木
322 声望19 粉丝

遇见超乎想象的自己!