Home » SQL & PL/SQL » SQL & PL/SQL » Please help - pivot option (oracle 11g, linux )
Please help - pivot option [message #646423] Wed, 30 December 2015 04:18 Go to next message
lb92
Messages: 3
Registered: December 2015
Junior Member
hi all,
please help i have a problem with pivot:
i am trying to run this command:

select * from
(
select 'AGG-DIRECT' as label_t ,FLIGHT_RT_AGG_STATUS as status,count(status)
from fs_cdr_control
where FLIGHT_RT_AGG_STATUS in(0,1,2,9)
group by FLIGHT_RT_AGG_STATUS
union all
select 'AGG-ME' as label_t ,hourly_ag_status as status,count(status)
from fs_ME_control
where hourly_ag_status in(0,1,2,9)
group by hourly_ag_status
union all
select 'AGG-RTB' as label_t ,hourly_ag_status as status,count(status)
from FS_RTB_control
where hourly_ag_status in(0,1,2,9)
group by hourly_ag_status
)
pivot
(
count(label_t)
for label_t in ('AGG-DIRECT','AGG-ME','AGG-RTB')
)
order by status;

i am out of ideas why it would not run, it returns me error: ora 00933 sql command not properly ended.

the inside query returns this:
label_t status count(*)
AGG-DIRECT 9 71163
AGG-ME 1 188
AGG-ME 9 70444
AGG-RTB 1 19
AGG-RTB 9 70672
AGG-RTB 0 42

all i want is to make it look like this:

the number are just examples:
this important part is
status AGG-DIRECT AGG-ME AGG-RTB
1 0 10 20
0 50 15 21
2 15 19 5
9 65 15 22

please help,
i am out of my mind.
Confused

[Updated on: Wed, 30 December 2015 04:30]

Report message to a moderator

Re: Please help - pivot option [message #646426 is a reply to message #646423] Wed, 30 December 2015 04:53 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

To show an error, use SQL*Plus and copy and paste your session, the WHOLE session.

Re: Please help - pivot option [message #646437 is a reply to message #646426] Wed, 30 December 2015 07:07 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>i am out of my mind.
Are you bragging or complaining here?

How are we to know when correct answer has been posted?
Re: Please help - pivot option [message #646444 is a reply to message #646437] Wed, 30 December 2015 09:31 Go to previous messageGo to next message
lb92
Messages: 3
Registered: December 2015
Junior Member
found solution by myself.
Re: Please help - pivot option [message #646445 is a reply to message #646444] Wed, 30 December 2015 09:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Which is?

Re: Please help - pivot option [message #646446 is a reply to message #646445] Wed, 30 December 2015 11:46 Go to previous message
lb92
Messages: 3
Registered: December 2015
Junior Member
There was no problem.

The query i added do the job i asked for, the problem was i mistakenly opened a different test database and it was oracle 10g r2 not 11g.

sorry for the trouble.

next time i will check everything before posting a question.


[Updated on: Wed, 30 December 2015 11:47]

Report message to a moderator

Previous Topic: Please help for resolving issue for UTL_FILE
Next Topic: Performance Issue in VARRAY
Goto Forum:
  


Current Time: Thu Apr 18 18:45:18 CDT 2024