ROW_NUMBER() OVER函数的基本用法
select * from ( select * ,row_number() over(partition by DDID order by DDID desc) y from LDZBSCJH where HTBH='V01461' ) as b where y <>1 SqlServer四种排序:ROW_NUMBER()/RANK()/DENSE_RANK()/ntile() over() 先看一下最简单的sql语句以及最原始的效果图: SELECT a.userName,a.userid FROM dbo.t_user a 【四种排序方式】 1.ROW_NUMBER()排序 我们将这几行数据进行简单的排序,另给一个新的列RN SELECT a.userName,a.userid,ROW_NUMBER()OVER (order by a.userName) AS RN FROM dbo.t_user a 这时,我想针对名字这一列,将重复的数据以1开头排序,不存在重复的就是1 SELECT a.userName,a.userid,ROW_NUMBER()OVER (partition by a.userName ORDER by a.userName) AS RN FROM dbo.t_user a 2.RANK()排序 SELECT a.userName,a.userid