Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Top n in sql

Re: Top n in sql

From: Giedrius <gurbonavicius_at_hotmail.com>
Date: Tue, 25 May 1999 11:52:31 +0200
Message-ID: <7ie338$eju$1@trimpas.omnitel.net>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US