嗨,请帮助我 我需要查询以下示例 在两个表日期字段相同日期来更多次或一次我需要输出查询只有每天一行不想重复的日子我们想要计算在同一两个表中的其他付款和税
离 table1
payment tax date
100 1.02 15-1-2010
23 0.09 15-1-2010
45 2.3 2-3-2011
table2
pay pdate
400 15-1-2010
253 18-1-2010
465 2-2-2011
我需要这样的输出
pay tax pdate
523 1.02 15-1-2010
465 0 2-2-2011
45 2.3 2-3-2011
答案 0 :(得分:0)
select sum(payment) pay, min(tax) tax, pdate
from
(
select payment, tax, date
from table1
union all
select pay, 0, pdate
from table2
) x
group by date
答案 1 :(得分:0)
select sum(payment) pay, sum(tax) tax, date pdate
from (select payment, tax, date
from table1
union all
select pay,0.0, pdate
from table2) t
group by pdate;