Update sheet3set a = X.A, B.=X.B, C=X.CFrom sheet3, (Select ID, Sum(a) a, sum(b) b, sum(C) c From (Select * from sheet1 union all Select * from sheet2 )Y Group By ID )XWhere sheet3.ID=X.ID
如果sheet3中没有记录,则执行下面SQLInsert into sheet3Select X.*From (Select ID, Sum(a) a, sum(b) b, sum(C) c From (Select * from sheet1 union all Select * from sheet2 )Y Group By ID )X Left Join sheet3 ON X.ID=sheet3.IDWhere sheet3.ID Is Null
子查询别名啊,(Select ID, Sum(a) a, sum(b) b, sum(C) c From (Select * from sheet1 union all Select * from sheet2 )Y Group By ID ) X 也可以写为(Select ID, Sum(a) a, sum(b) b, sum(C) c From (Select * from sheet1 union all Select * from sheet2 ) as Y Group By ID ) as X