Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query problem

Status
Not open for further replies.

kay7

Programmer
Joined
Dec 10, 2003
Messages
1
Location
US
I need a single Query which returns data in the follwoing conditions.
Query1
select project_id, sum(AMOUNT) as AMOUNT_A from TableA where Project_id like 'AB%' and Project_TYpe='A' Group BY Project_id

Query2
select Project_ID, sum(AMOUNT)as AMOUNT_B from TableA where Project_id like 'AB%' and Project_TYpe='B' Group BY Project_id

My query should return like the follwoing output
Project_ID AMOUNT_A Amount_B
Proj1 1200 0
Proj2 0 500

Any help is appreciated...

Thanks
KAY7
 
select
project_id,
sum(CASE WHEN Project_TYpe='A' THEN AMOUNT END) as AMOUNT_A,
sum(CASE WHEN Project_TYpe='B' THEN AMOUNT END) as AMOUNT_B
from TableA
where Project_id like 'AB%'
Group BY Project_id

If your DBMS doesn't support CASE look for DECODE/IIF

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top