1、查询第21-30条记录

select top 10 * from sys_Module where ID >
(
select max(ID) from (select top 20 * from sys_Module ) as a
)

查询结果:什么也 没有

1.1 执行 select max(ID) from (select top 20 * from sys_Module ) as a 发现结果为46(数据库中记录共46条)

1.2 执行select top 20 * from sys_Module,结果正确就是1-20的记录

为什么和在一起就不对了

原因:出现在from子句中的表我们称为派生表。派生表是虚拟的,未被物理具体化,也就是说当编译的时候,外部查询和内部查询会被合并,并生成一个计划。

select top 20 * from sys_Module 返回的是表sys_Module,select max(ID)从表sys_Module里查询。

2、正确方法

select top 10 * from sys_Module where ID >
(
select max(ID) from (select top 20 * from sys_Module order by ID) as a
)

select top 20 * from sys_Module order by ID ,而order by返回的不是表而是游标,top可以从order by返回的游标里选择指定数量生成一个表并返回。

select max(ID)从这个返回的表里查询。

最新文章

  1. debain 8安装为知笔记(how to install wiznote in debain 8)
  2. Use Excel Pivot Table as a BI tool
  3. c#中对rgb的使用
  4. C# DES加密解密用法
  5. C# 使用Salt+Hash来为密码加密
  6. css3学习--css3动画详解二(3d效果)
  7. Python进程、线程、协程详解
  8. Android常用ProgressDialog设置
  9. Android Studio 1.0 (稳定版) 完全攻略
  10. dsplay:table页面合并表格
  11. mysql存储过程且mybatis调用
  12. Gulp-自动化编译sass和pug文件
  13. 【HNOI2017】大佬
  14. springcould 微服务 搭建
  15. Java开发环境配置(5)--Web 服务器--Tomcat--安装过程遇到的问题
  16. Linux 小知识翻译 - 「小型移动式PC」
  17. Bias(偏差),Error(误差),和Variance(方差)的区别和联系
  18. Linux安装和设置Samba服务器
  19. iis下php 500错误
  20. 2. React组件的生命周期

热门文章

  1. EasyUI中combobox的代码实例
  2. 集训考试题tents
  3. 洛谷——P1405 苦恼的小明
  4. RPD Volume 168 Issue 4 March 2016 评论1
  5. websocket、文件上传
  6. Tomcat线程池实现
  7. 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem
  8. Problem S: 零起点学算法14——三位数反转
  9. 【MySQL笔记】MySql5安装图解教程
  10. 【java】处理时间字段 在数据库查询的时候只想要年月日,不想要时分秒 ,java中设置时间类型为年月日,java中设置Date中的时分秒为00.00.000