Home » SQL & PL/SQL » SQL & PL/SQL » query (oracle 9i)
query [message #414248] Tue, 21 July 2009 03:28 Go to next message
ora_2007
Messages: 430
Registered: July 2007
Location: Mumbai
Senior Member
select sku,location,sum(part_qty) from Demand_Daily_History
where sku = '10001'
group by sku,location


SKU      Location Qty
 
10001    CARSON   1
10001    VA       5

select sku, case location when 'CARSON' then sum(part_qty) end,
case location when 'VA' then sum(part_qty) end
from Demand_Daily_History
where sku = '10001'
group by sku,location


output:
SKU 	CARSON 	VA
 
10001 	1 	NULL
10001 	NULL 	5


Required
SKU               carson           VA
10001               1                   5

What logic i need to write to get required output.
Re: query [message #414251 is a reply to message #414248] Tue, 21 July 2009 03:50 Go to previous message
vamsi kasina
Messages: 2107
Registered: October 2003
Location: Riyadh, Saudi Arabia
Senior Member
Don't group by location.
Use sum(decode(location ,'CARSON',part_qty)) and sum(decode(location ,'VA',part_qty)).

By
Vamsi
Previous Topic: Reclaim allocated space to a table
Next Topic: Sql to loop through date
Goto Forum:
  


Current Time: Tue Dec 06 10:47:20 CST 2016

Total time taken to generate the page: 0.10436 seconds