Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem modifying a simple query into a subquery 1

Status
Not open for further replies.

jq65

Programmer
Feb 24, 2003
5
GB
The following simple query executes ok

select location_name, count(*)
from observation
where season (observation_date) = 'summer'
group by location_name;

Season is a function and the query returns the locations and number of occurences of a certain activity
I now want to modify it into a composite query that gives the name of the location with the largest number of observations in summer.

I am stumped with the logic

Any assistance would be gratefully appreciated

Thanks
 
Something like this should work ...

select location_name, count(*)
from observation
where season (observation_date) = 'summer'
group by location_name
having count(*) = (select max(count(*))
from observation
where season (observation_date) = 'summer'
group by location_name)

Greg.
 
Thanks for the suggestion Greg but this returns an error : "Subquery cannot return more than one result"
Also I only want the location with the maximum occurences
 
Greg

Thanks - I modified your code a little and it works fine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top