试试(比较直观的办法):select t.id,sum(t.total) from (select id,total from a UNION ALL select id,total from b) t group by t.id

解决方案 »

  1.   

    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
      

  2.   

    楼上的没有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;
      

  3.   

    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;
      

  4.   

    skystar99047(天星) 的結果出來了