Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Alias for a CASE WHEN expression in a SELECT cannot be used in GROUP BY?
I need some help explaining the following situation. I have tested the
case both in 9i and 10gR2.
Table:
EMPLOYEE
ID NUMBER(38) SALARY NUMBER
Original Query:
Intended Modification:
The modified query fails with
ERROR at line 6:
ORA-00904: "EMP_CLASS": invalid identifier.
I can create a VIEW
create view emp_class_view as
select
(case when salary>500000 then 'CLASS_A'
else 'CLASS_B' end) emp_class,
salary
from employees
Then the following query works fine:
select emp_class, sum(salary) from emp_class group by emp_class;
I am just having a hard time explaining it.
Thanks a lot
JH
Received on Sat Mar 04 2006 - 08:56:25 CST
![]() |
![]() |