文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>SQL语句的几种分页方法

SQL语句的几种分页方法

时间:2011-03-04  来源:冰-阳光

我的分页语句是这样的:

select top 15 id from table1 where leibieid=1 and ish=1 and
id not in(select top 90 id from table1 where leibieid=1 and ish=1 order by Gsrz desc,time desc)
order by  Gsrz desc,time desc

将这句SQL分解成单纯的查询:

select id from table1 where leibieid=1 and ish=1 order by Gsrz desc,time desc

得到如下数据:

而我使用的分页SQL得到的结果却是:

大家可以看到两次查寻得到的数据是完全不一样的,

下面给大家看一组分析数据:

为了能更直接的找到原因,我将查寻语句微改了下,

select top 15 id,gsrz,time from jzw_gs_zxgs where leibieid=1 and ish=1 and
id not in(select top 0 id from jzw_gs_zxgs where leibieid=1 and ish=1 order by Gsrz desc,time desc)
order by Gsrz desc,time desc


相当于这句SQL在执行的时候先执行了NOT IN的语句,查找到15条满足该条件的数据后

再对这些数据进行新一轮的排序。很明显的:逻辑就不对了!

然后我将SQL换成:

 SELECT TOP 15 id, FROM
(SELECT ROW_NUMBER() OVER (ORDER BY Gsrz desc,time desc) AS RowNumber,* FROM table1 where leibieid=1 and ish=1) AWHERE RowNumber > 15*(1-1)

测试结果:


与我想的结果完全是一样,但是效率却不好,然后我想到Top Max模式的分页方法,

但是很Top Max模式的分页方法难满足多列混合排序的情形,所以还是选择上一种方法

相关阅读 更多 +
排行榜 更多 +
方块枪战战场安卓版

方块枪战战场安卓版

飞行射击 下载
战斗火力射击安卓版

战斗火力射击安卓版

飞行射击 下载
空中防御战安卓版

空中防御战安卓版

飞行射击 下载