表A
no amt date
01 20 1996-01-04
02 15 1996-02-01
……表B
eno no eamt date
0101 01 10 1996-01-10
0201 01 -5 1996-01-15
0301 01 -30 1996-02-09
0102 02 15 1996-02-02
0202 02 -10 1996-02-13
……
请问如何求1996-02-01以后的amt、eamt的和,sql语句。
no amt date
01 20 1996-01-04
02 15 1996-02-01
……表B
eno no eamt date
0101 01 10 1996-01-10
0201 01 -5 1996-01-15
0301 01 -30 1996-02-09
0102 02 15 1996-02-02
0202 02 -10 1996-02-13
……
请问如何求1996-02-01以后的amt、eamt的和,sql语句。
where a.date>'1996-02-01' and b.date> '1996-02-01'
group by a.no
select a.no,b.eamt,sum(a.amt) amt
from a left join (select no,sum(eamt) eamt from b where date > '1996-02-01' group by no) b
on a.no = b.no
where a.date > '1996-02-01'
group by a.no,b.eamt
(select no,amt from A where date > '1996-02-01'
union all
select no,eamt from B where date > '1996-02-01'
) group by no
(select no,amt from A where date > '1996-02-01'
union all
select no,eamt from B where date > '1996-02-01'
) t group by no
a.no,b.eamt,sum(a.amt) as amt
from
a
left join (select no,sum(eamt) eamt from b where date > '1996-02-01' group by no) b
on
a.no = b.no
where
a.date > '1996-02-01'
group by
a.no,b.eamt