从Mysql多个表中聚合数据

条件:表属性 A B,表1 表2

结果:以属性A为key,获取表1 2 中B值的总和 并依A排序

 

select A, sum(B) from ((select A,B from 表1) union all (select A,B from 表B)) result group by A order by A;

posted @ 2016-02-16 19:17  庚午大侠  阅读(1359)  评论(0编辑  收藏  举报