SQL Server添加序号列
使用ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN)为查询结果添加序号列
row_number() over(partition by col1 order by col2)表示根据col1分组,在分组内部根据col2排序,而此函数计算的值就表示每组内部排序后的顺序编号
例如:
select ROW_NUMBER() OVER(ORDER BY Convey_Fee desc) as z,rank() OVER(ORDER BY Convey_Fee desc) as z,DENSE_RANK() OVER(ORDER BY Convey_Fee desc) as z,NTILE(4) OVER(ORDER BY Convey_Fee desc) as z,(select sum(1) from Consign_D where Convey_Fee<=a.Convey_Fee) num,(select sum(1) from Consign_D where Convey_Fee<a.Convey_Fee) num1,Convey_Fee from Consign_D a order by Convey_Fee desc
结果:
作者:sy
出处:http://www.cnblogs.com/sydeveloper
QQ:522733724
本页版权归作者和博客园所有,欢迎转载,但未经作者同意必须保留此段声明,
且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利