首页 > 解决方案 > SQL Server如何确定row_number中order by子句中未使用的其他列的顺序

问题描述

我必须row_number基于一个col1生成,所以我在col1上使用order by,但是对应的col2是如何排序的,总是相同的顺序还是不同的顺序?

下面的例子:

create table #2 (id int, user_id int, building varchar(10))

insert into #2 (id, user_id, building)
select 1,11,'First'
union all
select 2,13,'First'
union all
select 3,12,'First'
union all
select 4,15,'Second'
union all
select 5, 14,'Second'

select 
    *,
    row_number() over (order by building) 
from #1 

user_id列的顺序是如何确定的?

标签: sql-server

解决方案


推荐阅读