sql server中行号的问题 [英] problem in row number in sql server
本文介绍了sql server中行号的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI
我有一张桌子像
college_code男女主题
101 10 25 AAA
101 15 11 BBB
223 15 12 AAA
223 15 12 BBB
223 15 12 CCC
331 11 12 AAA
我希望像这样记录
srno college_co男性女性主题
1 101 10 25 AAA
2 101 15 11 BBB
1 223 15 12 AAA
2 223 11 11 BBB
3 223 13 15 CCC
1 331 11 12 AAA
怎么可能使用行号
谢谢advance
解决方案
尝试以下代码...
SELECT
Rank() over ( Partition by college_code 订单 by college_code,subject) as 排名,college_code,男性,女性,主题
FROM
学院
组 按
college_code,男,女,主题
订单 按
college_code asc
它是pos sible ...
1.编写一个精选查询,例如......
select * from table_name,其中code ='101'
2。检查选择了多少行
3.选择行+ 1
i希望这有点帮助
您可以使用以下示例代码:
SELECT ROW_NUMBER( ) OVER ( ORDER BY college_code)< span class =code-keyword> AS srno,college_code,male,female,subject
FROM XYZ
HI
I have a one table like
college_code male female subject
101 10 25 AAA
101 15 11 BBB
223 15 12 AAA
223 15 12 BBB
223 15 12 CCC
331 11 12 AAA
and i want to record like this
srno college_code male female subject
1 101 10 25 AAA
2 101 15 11 BBB
1 223 15 12 AAA
2 223 11 11 BBB
3 223 13 15 CCC
1 331 11 12 AAA
how to this possible using row number
Thanks to advance
解决方案
Try the below code...
SELECT Rank() over (Partition by college_code Order by college_code, subject) as ranks, college_code, male, female, subject FROM College Group By college_code, male, female, subject Order by college_code asc
it is possible...
1.write a select query like...
select * from table_name where code='101'
2.check how many row selected
3.selected row + 1
i hope this helps a bit
You can use the following sample code:
SELECT ROW_NUMBER() OVER (ORDER BY college_code) AS srno, college_code , male, female, subject FROM XYZ
这篇关于sql server中行号的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文