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: Örjan Lundberg <orjanlundberg_at_my-dejanews.com>
Date: Sat, 5 Jun 1999 23:49:35 +0200
Message-ID: <7jc69s$3j8$1@news.luth.se>


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

Original text of this message

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