首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-09-15 
sql分页 翻页的优化??前台是extjs 后台c# 接收前台的start 和limit参数 进行分页翻页sql语句如下SQL codes

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; 

热点排行