Reputation: 91
TIA for any help/advice/further reading.
I'm trying to make SQLDev do a count of how many packages customers have had and then only show the top 10 of those results.
So I have this....
select pickup_customer , count (pickup_customer)
from
( select pickup_customer, count (pickup_customer)
from manifest
order by count (pickup_customer) desc )
where ROWNUM <= 10
group by pickup_customer
order by count (pickup_customer) desc
With that I'm getting 'Not a single group function' and I can't figure out where it's gone wrong. Probably very simple fix, I just can't see it right now!
EDIT: I have tried this code but am getting a 'missing right parenthesis ' error now!
select pickup_customer , count (pickup_customer)
from
(select pickup_customer, count (pickup_customer) --sub-query which pre-orders the results for rownum to then limit.
from manifest
order by count (pickup_customer) desc
group by pickup_customer)
where ROWNUM <= 10 -- limits the results to be only the top 10
Upvotes: 1
Views: 170
Reputation: 8152
The following query should work.
SELECT pickup_customer, COUNT (pickup_customer)
FROM enrollment
WHERE ROWNUM <= 10
GROUP BY pickup_customer
ORDER BY COUNT (pickup_customer) DESC
Upvotes: 2