dbTalk Databases Forums  

Pivot query in oracle- Please help!!

comp.databases.oracle comp.databases.oracle


Discuss Pivot query in oracle- Please help!! in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
longhorntx
 
Posts: n/a

Default Pivot query in oracle- Please help!! - 03-17-2005 , 08:49 AM






I have a table with following values

City STATE COLOR REGION
city1 Texas White SW
city2 Texas Gray SW
city3 Texas Gray SW
city4 Nevada Gray PAC
c5 Texas Yellow SW
c6 Florida Yellow SE
c7 Missouri Orange W
c8 Texas Orange SW

I am trying to create a report which looks like:

STATE White Gray Yellow Orange
Texas 1 2 0 1
Nevada 0 1 0 0
Florida 0 0 1 0
Missouri 0 0 0 1


I need to do this in oracle pl/sql
I tried to write this query

select state,
SUM( decode(color,'Orange',count(state),0) ) as orange,
SUM( decode(color,'Yellow',count(state),0) ) as yellow,
SUM( decode(color,'Gray',count(state),0) ) as gray
SUM( decode(color,'White',count(state),0) ) as white
from my_table
group by color

This query gives me an error "ORA-00937: not a single-group group
function"
Please help !
any ideas???


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.