select C.id,sum(C.total) as total from (select * from A union all select * from B) as C order by sum(C.total) desc
楼上的没有group by,语句本身就是错误的,一楼的差不多。 select t.id,sum(t.total) from (select id,total from a UNION ALL select id,total from b) t group by t.id order by sum(t.total) desc;
select id,sum(total) from (select id,total from a UNION ALL select id,total from b) group by id order by sum(total) desc;
C.id,sum(C.total) as total
from
(select * from A union all select * from B) as C
order by
sum(C.total) desc
select t.id,sum(t.total) from (select id,total from a UNION ALL select id,total from b) t group by t.id order by sum(t.total) desc;