Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Top n in sql
This one should be correct:
select * from (select count(*) num from logtable group by userid) a1 where 5 <= (select count(*) num from (select count(*) from logtable group by userid) a2
where a1.num > a2.num)order by 1
>
>
>Doug Brown wrote in message <7ic8td$ao3_at_news.abbott.com>...
>>I want to return the top 5 users of yesterdays internet. I have a log
>table
>>that has userid and date visited.
>>
>>select count(*)
>>from logtable
>>group by userid
>>order by count(*) desc
>>
>>but I want to stop after the top five are returned.
>>
>>Anyone know this one?
>>
>>Thanks
>>Doug Brown
>>
>>
>
>
Received on Tue May 25 1999 - 04:52:31 CDT
![]() |
![]() |