sql 分页的两种写法

Posted Debugs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 分页的两种写法相关的知识,希望对你有一定的参考价值。

string Strsql = string.Format(@"select ee.DOCUMENTNO,ee.APPLICANTNAME,ee.COMPANY,ee.REQUESTTIME,ee.REQ_TITLE, ee.INCIDENT,
(datediff(d,getdate(),STARTTIME)) STARTTIME,cc.STEPLABEL
,isNull((select distinct USERNAME from ORG_USER where LOGINNAME = substring(ASSIGNEDTOUSER,8,len(ASSIGNEDTOUSER)-7)),
substring(ASSIGNEDTOUSER,8,len(ASSIGNEDTOUSER)-7)) ASSIGNEDTOUSER, (datediff(d,getdate(),REQUESTTIME))AS DAYTIME,
BB.ROWNUMBER
from
(select AA.*, ROW_NUMBER() OVER(ORDER BY INCIDENT ) AS ROWNUMBER
from (Select distinct tt.INCIDENT, tt.STEPLABEL From UltimusDB.dbo.TASKS tt,PFT_REQ_MSTR reqmstr
where tt.INCIDENT = reqmstr.INCIDENT
and tt.STEPLABEL in (‘问题接收‘,‘处理行动反馈‘,‘问题经验总结‘,‘客户反馈结果‘)
and tt.STATUS=1) AA)
BB, UltimusDB.dbo.TASKS CC,PFT_REQ_MSTR ee
Where BB.ROWNUMBER between ({0}-1)*{1}+1 and {2}*{3}
and cc.INCIDENT = BB.INCIDENT
and cc.INCIDENT = ee.INCIDENT
and cc.STEPLABEL in (‘问题接收‘,‘处理行动反馈‘,‘问题经验总结‘,‘客户反馈结果‘)
and cc.STATUS=1
order by bb.ROWNUMBER", pageIndex, pageSize, pageIndex, pageSize);

 

 

 

-----

 

string Strsql = string.Format(@"SELECT TOP {0} * FROM (select DOCUMENTNO,APPLICANTNAME,a.COMPANY,REQUESTTIME,REQ_TITLE,a.INCIDENT, (datediff(d,getdate(),STARTTIME)) STARTTIME,
STEPLABEL,
isNull((select distinct USERNAME from ORG_USER where LOGINNAME = substring(ASSIGNEDTOUSER,8,len(ASSIGNEDTOUSER)-7)),
substring(ASSIGNEDTOUSER,8,len(ASSIGNEDTOUSER)-7)) ASSIGNEDTOUSER ,(datediff(d,getdate(),REQUESTTIME)) AS DAYTIME ,
ROW_NUMBER() OVER (ORDER BY REQUESTTIME desc) AS RowNumber
from ProfitBPMProcess.dbo.PFT_REQ_MSTR a left join UltimusDB.dbo.TASKS b
on a.INCIDENT=b.INCIDENT where b.STATUS=1) A WHERE RowNumber > {1}*({2}-1) order by REQUESTTIME,APPLICANTNAME desc", pageSize, pageSize, pageIndex);

以上是关于sql 分页的两种写法的主要内容,如果未能解决你的问题,请参考以下文章

EasyUI Pagination 分页的两种做法

查询分页的几种Sql写法

SQL Server分页的存储过程写法以及性能比较

前端实现el-pagination分页的两种业务场景,你知道吗?

前端实现el-pagination分页的两种业务场景,你知道吗?

SQL Server两种分页性能比较