Re: finding ordinal position in a result set?

From: Thomas Kellerer <OTPXDAJCSJVU_at_spammotel.com>
Date: Wed, 22 Jul 2009 12:19:04 +0200
Message-ID: <7co7crF28i1ofU1_at_mid.individual.net>



mh_at_pixar.com, 22.07.2009 12:11:
> Suppose I have a query like the following.
> What's the best way to find the position of a particular item?
> e.g. I would like to find out that:
>
> 'fred' is position 3 of 4 total.
>
>
> select seq,name from tbl order by seq;
> seq name
> --- ----
> 2 bob
> 5 able
> 8 fred
> 9 steve

Use the row_number() function

select seq, name, row_number() over (order by seq) from tbl
order by seq; Received on Wed Jul 22 2009 - 05:19:04 CDT

Original text of this message