Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL prodecure to compute ranking
There is a potential problem with a solution of this type, that depends on the requirements for tied places. The rownum is not the rank if you have tied scores.
-- Regards Jonathan Lewis http://www.jlcomp.demon.co.uk Next Seminar dates: (see http://www.jlcomp.demon.co.uk/seminar.html ) ____England______September 24/26, November 12/14 ____USA__________November 7/9 (MI), 19/21 (TX) The Co-operative Oracle Users' FAQ http://www.jlcomp.demon.co.uk/faq/ind_faq.html Candido Dessanti wrote in message <3D7F51D6.1090801_at_blunet.it>...Received on Thu Sep 12 2002 - 16:31:27 CDT
>that's solution of mine if you dont want to
>use oracle's analytic functions
>
>select b.* from
>(select rownum as rank,
> id_user,
> points
> from (select * from users
> order by points desc)
>) a,
>(select rownum as rank,
> id_user,
> points
> from (select * from users
> order by points desc)
>) b
>where a.id_utente=5
>and b.rank < a.rank+3
>and b.rank > a.rank-3
>/
>
>would this fits your requirements?
>(just 2 sorts maybe avoidable with indexes)
>