Home  >  Article  >  Database  >  How to solve the problem of not sorting when sqlServer uses ROW_NUMBER

How to solve the problem of not sorting when sqlServer uses ROW_NUMBER

coldplay.xixi
coldplay.xixiforward
2020-07-24 17:43:273190browse

How to solve the problem of not sorting when sqlServer uses ROW_NUMBER

Set sqlServer not to sort when using ROW_NUMBER

--1. Seeing that NHibernate writes paging like this, I feel that it is easier to understand when writing (it should not be efficient) Question?)
--with is just an alias?

[sql]

with query as (select ROW_NUMBER() over(order by (select 0)) AS ROWNUM, * FROM Product) 
select * from query where ROWNUM BETWEEN 5 AND 10

--2.ROW_NUMBER must refer to over (order by **). Sometimes I don’t want to sort at all and want to sort in the original order (sorting also requires Time)

--The method is:

select ROW_NUMBER() over(order by (select 0)) AS ROWNUM,* FROM Product

The sorting is:

select Row_number() over(order by Oper_Date desc) AS ROWNUM,* FROM Product

Related learning recommendations: mysql video Tutorial

The above is the detailed content of How to solve the problem of not sorting when sqlServer uses ROW_NUMBER. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete