Sql server 林氏;SQL Server:按起始行排序
我有一个表,它有三列:Sql server 林氏;SQL Server:按起始行排序,sql-server,entity-framework,partial-ordering,sql-order-by,Sql Server,Entity Framework,Partial Ordering,Sql Order By,我有一个表,它有三列:username、followerCount和CreateDate 表中大约有110000个用户,我试图显示按followerCount排序的用户。我的工作如下: select top 50 * from Users where followerCount <= @followerCount order by followerCount desc, createDate desc 选择前50名* 来自用户 如果followerCount只需跟踪您所在的页面,然后
username
、followerCount
和CreateDate
表中大约有110000个用户,我试图显示按followerCount
排序的用户。我的工作如下:
select top 50 *
from Users
where followerCount <= @followerCount
order by followerCount desc, createDate desc
选择前50名*
来自用户
如果followerCount只需跟踪您所在的页面,然后您就可以使用Skip和Take为您进行分页:
var page=9; //Set to whatever page you want
var pageSize=50;
var results=db.Users
.OrderByDescending(u=>u.followerCount)
.ThenByDescending(u=>u.createDate)
.Skip((page-1)*pageSize)
.Take(pageSize);
如果您需要存储过程为您执行分页,那么您需要了解SQL Server(2012年以前)或更新版本的工作原理。单个参数@followerCount不足以定义所需内容。如果您在SQL Server 2012中使用EF6.1.2+,则可以通过OFFSET FETCH