用含NULL值的字段也不会影响排序: create table tb(id int ,col nvarchar(10)) insert into tb select 1,'aa' union all select 2,'bb' union all select 3,null union all select 4,'' go select id,row_number()over (order by col) as rownumber from tb --order by id go drop table tb /* id rownumber ----------- -------------------- 3 1 4 2 1 3 2 4(4 行受影响) */ 一定是你哪儿有什么不对的地方了.
create table tb(id int ,col nvarchar(10))
insert into tb select 1,'aa'
union all select 2,'bb'
union all select 3,null
union all select 4,''
go
select id,row_number()over (order by col) as rownumber from tb --order by id
go
drop table tb
/*
id rownumber
----------- --------------------
3 1
4 2
1 3
2 4(4 行受影响)
*/
一定是你哪儿有什么不对的地方了.