SQL Row_Number() function in Where Clause without ORDER BY?

前端 未结 5 1138
北海茫月
北海茫月 2020-12-08 06:45

I found a bunch of questions on this topic with nice solutions but none of them actually deal with what to do if the data is not to be ordered in one specific way. For insta

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 07:07

    I use this to suppress the sort:

    ORDER BY @@rowcount
    

    @@rowcount is constant within the query. Example:

    select N = row_number() over (order by @@rowcount) from sys.columns
    

    Use of (select 0) in the ORDER BY seems to run much slower.

提交回复
热议问题