[英]For a given table give out the count for each row Oracle SQL
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). 因此它给出了每一行的数量,但是我不知道该怎么做(是SQL的初学者)。 Any tips?
有小费吗?
Simply use row_number()
: 只需使用
row_number()
:
select row_number() over (order by id) as "Count",
t.*
from t
order by "Count";
You should have both order by
s to be sure the numbering on the rows is correct and the order of the rows in the result set is correct. 您应该同时
order by
s来order by
以确保行上的编号正确并且结果集中的行顺序正确。
use dense_rank()
使用
dense_rank()
select *,dense_rank() over(order by id) from t
or you could use count()
或者你可以使用
count()
select *,count(*) over(order by id) from t
简单
select rownum, ID , Name, Payment from table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.