Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using "having" on SQL Plus

Author  Topic 

antgaudi
Starting Member

4 Posts

Posted - 2009-04-19 : 16:15:06
I have the following code:

select pil_pilotname, pil_flight_pay
from pilots
group by pil_pilotname, pil_flight_pay
having pil_flight_pay > 2586.67
/


I wanted to use avg(pil_flight_pay) instead of 2586.67. SQL, however, does not allow.
I'm trying to get the flight pays that exceed the average flight pay for all pilots.

What should I modify?

Thanks.

nathans
Aged Yak Warrior

938 Posts

Posted - 2009-04-19 : 16:39:21
You can move into subquery:

select pil_pilotname, pil_flight_pay
from pilots
where pay > (select avg(pil_flight_pay) from pilots)


Nathan Skerl
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2009-04-19 : 16:44:54
Just realized you ref SQL Plus... this is a MSSQL forum, though I believe the tsql I posted will work in Oracle as well :)
Go to Top of Page

antgaudi
Starting Member

4 Posts

Posted - 2009-04-19 : 18:24:13
It worked!
Thanks!
Go to Top of Page
   

- Advertisement -