当前位置: 代码迷 >> Sql Server >> sql分页 翻页的优化?该怎么解决
  详细解决方案

sql分页 翻页的优化?该怎么解决

热度:69   发布时间:2016-04-27 11:35:51.0
sql分页 翻页的优化??
前台是extjs 后台c# 接收前台的start 和limit参数 进行分页 翻页
sql语句如下  
SQL code
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....)
变成了
SQL code
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

现在问题来了 速度很慢  
应该如何优化??

------解决方案--------------------
C# code
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;
  相关解决方案