您可以在分组依据之前合并表(顺便说一下,这在Oracle上):
SELECt t.month_ref, SUM(t.amount1), SUM(t.amount2) FROM (SELECt month_ref, amount1, amount2 FROM T_FOO WHERe seller = XXX UNIOn ALL SELECt month_ref, amount1, amount2 FROM T_BAR WHERe seller = XXX ) t GROUP BY t.month_ref
您还可以将表与卖方字段合并,并在以后进行过滤(以防您需要更高级的逻辑):
SELECt t.month_ref, SUM(t.amount1), SUM(t.amount2) FROM (SELECt month_ref, amount1, amount2, sellerFROM T_FOO UNIOn ALL SELECt month_ref, amount1, amount2, sellerFROM T_BAR) t where t.seller = XXX GROUP BY t.month_ref



