We help IT Professionals succeed at work.
Get Started

Invalid Identifier in Oracle Pivot query

bmsande asked
Last Modified: 2015-10-12
I'm attempting to pivot a result set on the oracle "ROWNUM" column with no such luck thus far.  My current result set returns the following:

1	user1
2	user2
3	user3

Open in new window

The rownum column represents the most active user in the result set (1 being most active), so I want to pivot on ROWNUM to show columns 1-3, with the value being NAME.  Here is the query that I came up with, which returns an 'invalid identifier' (ROWNUM) in the pivot section of the query...

select * from (
select ROWNUM, NAME from 
(SELECT BB.ID,bb.name, COUNT(auditid) as NumReads FROM DAUDITNEW aa, KUAF bb WHERE auditdate > SYSDATE - 180 AND aa.performerid = bb.id AND ( AA.AUDITSTR ='View' or AA.AUDITSTR='Fetch')
AND BB.ID <> 9471817 AND AA.DATAID in (select dataid from dtree start with dataid=19628279 connect by prior dataid=parentid) GROUP BY BB.ID,bb.name ORDER BY COUNT(auditid) DESC
where rownum < 4
  max(name) for ROWNUM in ('1','2','3')

Open in new window

Error:  ORA-00904: : invalid identifier

Any ideas?
Watch Question
Most Valuable Expert 2012
Distinguished Expert 2020
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE