Re: query for ordering

Re: query for ordering

 

  

This should do:
CREATE TABLE T(c1 INT, c2 INT);

SELECT c1, c2 FROM (SELECT ROW_NUMBER() OVER(PARTITION BY c1 ORDER BY c2)
AS rn, c1, c2 FROM T) AS X
WHERE rn <= 3;

Cheers
Serge




"Madhu Chandran S "
<db2udbdba-ezmlmshield-x68105042.[Email address protected] wrote on
11/28/2005 07:41:51 AM:

> Hi all,
> I am very new to db2 and want to know about this simple query.
> I have a table where there are 3 groups of items.I want to select the top
> 3 items in each group.I tried using count() but the query is not working.
> please revert back with some possible queries.
>
> Thanks and regards,
> Madhu
>
>
>
> ---------------------------------------------------------------------
> PLEASE CLICK REPLY-ALL TO SEND A REPLY TO EVERYONE
> website: http://www.LazyDBA.com
> To unsubscribe: http://www.lazydba.com/unsubscribe.html
>


DB2 & UDB email list listserv db2-l LazyDBA home page