日期:2014-05-17  浏览次数:20392 次

看看这条SQL的效率


select top 5 * from hotel h --5:返回行数
where h.hid > (select max(abc.hid) from (select top 10 hid from hotel ORDER BY hid) abc)--10:起始行数



分页的,返回了11-15行,不知道效率高不.
顺便求一条无可挑剔的高效率分页语句,只要支持SQL SERVER 2005就可以了
------最佳解决方案--------------------
select * from
 (select row_number() over(hid) as [rownum],* from hotel) a
 where a.[rownum]> 10 and a.[rownum]<=15

上面有错,参考这句
------其他解决方案--------------------
引用:
引用:对比效率的一搜一大把啊

我怎么感觉那些效率不高啊 尤其用NOT IN那些..



不要感觉

要测试,用数据说话。呵呵
------其他解决方案--------------------
引用:
...over(order by hid)...
是应该加上order by

引用:
不要感觉

要测试,用数据说话。呵呵

呃,你不满意“感觉”啊,这个容易,你去网上搜一下,网上已经有人有测试数据

引用:
那样不是有点浪费资源吗..数据要实时的话不是每次刷新都要读100条?
这个好像要看在哪应用吧,WEBFORM或WINFORM
------其他解决方案--------------------
select * from (select row_number() over(hid) as [rownum],{0} from hotel {2}) as a where a.[rownum]> 10 and a.[rownum]<=15

感觉条件里不要加查询
------其他解决方案--------------------

select?top?5?*?from?hotel?h?--5:返回行数
where?h.hid?>ANY?(select?top?10?hid?from?hotel?ORDER?BY?hid)--10:起始行数

------其他解决方案--------------------
对比效率的一搜一大把啊

------其他解决方案--------------------
可先将前100页数据: select top 500 * from hotel
查询结果集放在Recordset里,然后在前端程序里实现翻页,
不必每次翻页都要去查询数据库.
------其他解决方案--------------------
引用:
对比效率的一搜一大把啊


我怎么感觉那些效率不高啊 尤其用NOT IN那些..
------其他解决方案--------------------
引用:
SQL code



123

select * from (select row_number() over(hid) as [rownum],* from hotel) a  where a.[rownum]> 10 and a.[rownum]<=15
上面有错,参考这句



好像要改成select * from (
select row_number() over(order by hid) as [rownum],* from hotel) a  
where a.[rownum]> 10 and a.[rownum]<=15 

才能运行..
------其他解决方案--------------------
引用:
可先将前100页数据: select top 500 * from hotel
查询结果集放在Recordset里,然后在前端程序里实现翻页,
不必每次翻页都要去查询数据库.


那样不是有点浪费资源吗..数据要实时的话不是每次刷新都要读100条?