Solved

Group By SubQuery...

Posted on 2006-11-07
3
1,005 Views
Last Modified: 2008-01-09
Hi experts,

I would like to group by the subquery but when I try I get the error "ORA-22818: subquery expressions not allowed here."

What am I doing wrong or what is the alternative? Thanks.

My query:

select distinct
count(p.person_code) as emacount,
(select byd_acc_year from brom_year_dates
where byd_fund_year = ema.FUNDING_YEAR)
from people p, ema
where p.EMA_ID is not null
and ema.PERSON_CODE = p.PERSON_CODE
and ema.FUNDING_YEAR = 13
group by (select byd_acc_year from brom_year_dates
where byd_fund_year = ema.FUNDING_YEAR)
0
Comment
Question by:bromley_college
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 17887741
what about this:
select count(person_code) emacount, x
from (
select p.person_code ,
(select byd_acc_year from brom_year_dates
where byd_fund_year = ema.FUNDING_YEAR) x
from people p, ema
where p.EMA_ID is not null
and ema.PERSON_CODE = p.PERSON_CODE
and ema.FUNDING_YEAR = 13
)
group by x
0
 

Author Comment

by:bromley_college
ID: 17887779
I am expecting something like

EMACOUNT     X
613                0607
501                0506
714                0405


However, your query just gives me:
EMACOUNT     X
613                0607


0
 

Author Comment

by:bromley_college
ID: 17887788
Nope sorry, my fault. I didn't need the line "and ema.FUNDING_YEAR = 13"

Your query works fine. Thank you :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to recover a database from a user managed backup

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question