How to group by alias in Oracle

1137030 pts.
Tags:
Oracle
Oracle Query
How would I be able to "group by" a query using an alias. Something like this:
select count(*), (select * from....) as alias_column 
from table 
group by alias_column
The only thing is that I keep getting this 'alias_column' : INVALID_IDENTIFIER error message. What should I do here?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.
Hi,

Nest the query with the alias column

select count(*), alias_column
from
( select empno, (select deptno from emp where emp.empno = e.empno) as alias_column
  from emp e
)
group by alias_column;

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • paddison51
    I am building a flat file with a mix of fields that contain literals and data from columns in other tables. I am using alias names for all the fields in the output. I am summing some fields and counting others. How do I handle the fields with literals in a group by if I cannot reference the alias names?

    Select 'field_one' as column_1, table_column as column_2
    from table_one
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: