SQL join and aggregate query

Table A1:
NAME
YEAR
AMT
A
2008
1000
B
2009
1120
A
2009
1150
C
2003
520
C
2009
1280
A
2008
9

Table A2:
NAME
YEAR
STATUS
A
2009
NEW
B
2008
NEW
C
2008
OLD
A
2009
NEW
B
2009
OLD

Write a query to calculate total AMT for each NAME with NEW STATUS :

select A1.NAME, SUM(A1.AMT)
from A1, A2
where A1.NAME = A2.NAME 
and A2.STATUS = 'NEW'
group by A1.NAME;

No comments :

Post a Comment