0

if i have a table like this:

ID  | Name   | Payment
----------------------
101 | Victor | 10
103 | Andy   | 13
134 | Mai    | 2
156 | Chris  | 68
179 | Ryan   | 43

And I wanna have a query that gives out the following

[Count] | ID  | Name   | Payment
----------------------
1       | 101 | Victor | 10
2       | 103 | Andy   | 13
3       | 134 | Mai    | 2
4       | 156 | Chris  | 68
5       | 179 | Ryan   | 43

So it gives out the number of each row but I don't know how to do it ( am a beginner at SQL). Any tips?

3 Answers 3

2

Simply use row_number():

select row_number() over (order by id) as "Count",
       t.*
from t
order by "Count";

You should have both order bys to be sure the numbering on the rows is correct and the order of the rows in the result set is correct.

Sign up to request clarification or add additional context in comments.

Comments

0

use dense_rank()

select *,dense_rank() over(order by id) from t

or you could use count()

  select *,count(*) over(order by id) from t

Comments

0

simple

select rownum, ID , Name, Payment from table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.