sql分页 翻页的优化??

jiery666 2012-08-19 09:36:50
前台是extjs 后台c# 接收前台的start 和limit参数 进行分页 翻页
sql语句如下

select top " + limit + " * from View_jydhwxx where fgsbm in (" + fgsbm + ") and jhrq >= '" + jdsj1 + "' and jhrq <= '" + jdsj2 + "' and jydbh not in(select top " + start + " jydbh from View_jydhwxx where fgsbm in (" + fgsbm + ") and jhrq >= '" + jdsj1 + "' and jhrq <= '" + jdsj2 + "' order by jydbh desc) order by jydbh desc


以上的语句是没有问题的 速度也还可以接受 ,但是 现在我又在上面的语句中加入了一个条件 dzzbm in ("+result+") 如 dzzbm in (001,002,003,004,005,006,007....)
变成了
select top " + limit + " * from View_jydhwxx where fgsbm in (" + fgsbm + ") and dzzbm in ("+result+") and jhrq  >= '" + jdsj1 + "' and jhrq  <= '" + jdsj2 + "' and jydbh not in(select top " + start + " jydbh from View_jydhwxx where fgsbm in (" + fgsbm + ") and dzzbm in ("+result+") and jhrq  >= '" + jdsj1 + "' and jhrq  <= '" + jdsj2 + "' order by jydbh desc) order by jydbh desc

现在问题来了 速度很慢
应该如何优化??
...全文
77 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiery666 2012-08-19
  • 打赏
  • 举报
回复
基本解决了我的问题

where rn between " + start + " and " + start+limit;
这个错了 start+limit 没有转换过来
人生无悔 2012-08-19
  • 打赏
  • 举报
回复

string sql="select * from (
select row_number() over(order by name) rn,* from View_jydhwxx where fgsbm
in (" + fgsbm + ") and jhrq >= '" + jdsj1 + "' and jhrq <= '" + jdsj2 + "'
order by jydbh desc) t
where rn between " + start + " and " + start+limit;

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧