Need to know the position of the record of a statement select

Hello

I think I can explain what I need graphycally bettar than with words.

I have the current selection:
SELECT T1, T2, T3 OF THE TEST

and the result is:

T1 T2 T3

Renault Megane 14000
Renault Clio 9000
Ford Focus 16000


Okay, I need to know how to change this selection so that I can get something like


T1 T2 T3 POSITION

Renault Megane 1 14000
Renault Clio 2 9000
Ford Focus 3 16000

When the POSITION is the position of the record came from the tail.

Thx for your time

Hello

Use the ROWNUM Pseudo-column:

SELECT  t1, t2, t3
,       ROWNUM  AS position
FROM    test;

If you add an ORDER BY clause to your query, ROWNUM will not necessarily take account of this order.
If you want the numbers assigned in order, use the ROW_NUMBER analytic function instead of ROWNUM.
For example:

SELECT    t1, t2, t3
,         ROW_NUMBER () OVER ( ORDER BY  t1  DESC
                               ,         t2
                             )  AS position
FROM      test
ORDER BY  t1  DESC
,         t2;

Published by: Frank Kulash, 28 May 2009 05:04

Tags: Database

Similar Questions

Maybe you are looking for