Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Top n in sql
select userid, count FROM (
select userid, count(*) as count from A
group by userid
order by 2 desc)
where ROWNUM <6;
should do it.
<genebarkin_at_my-deja.com> wrote in message
news:7j11rv$95d$1_at_nnrp1.deja.com...
> add in a having clause after the group by:
> HAVING count(*) >= 5
>
>
> In article <7ic8td$ao3_at_news.abbott.com>,
> "Doug Brown" <Doug.Brown_at_abbott.com> wrote:
> > 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
> >
> >
>
>
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
Received on Sat Jun 05 1999 - 16:49:35 CDT
![]() |
![]() |