查询不连续的数据
2010-10-09 20:41
197 查看
一般查询可以这样:
Code:
select * from tbxx where id between 5 and 10
或者其它,但这有一个条件,就是id必须连续。
Code:
select * from tbsickinfo
那我要查询20到300的:之间有10条数据,就这样写
Code:
select top 10 * from tbsickinfo where sid not in (select top 20 sid from tbsickinfo)
看这张图会发现2010092414就跳到2010092515,还有如果中间有些数据删除的话这种情况也适用
Code:
select top 5 * from tbsickinfo where sid not in (select top 14 sid from tbsickinfo)
not in先把前面14条去掉,再查询前5条数据。也就是查询第15到第19条数据。
Code:
select * from tbxx where id between 5 and 10
或者其它,但这有一个条件,就是id必须连续。
Code:
select * from tbsickinfo
那我要查询20到300的:之间有10条数据,就这样写
Code:
select top 10 * from tbsickinfo where sid not in (select top 20 sid from tbsickinfo)
看这张图会发现2010092414就跳到2010092515,还有如果中间有些数据删除的话这种情况也适用
Code:
select top 5 * from tbsickinfo where sid not in (select top 14 sid from tbsickinfo)
not in先把前面14条去掉,再查询前5条数据。也就是查询第15到第19条数据。
相关文章推荐
- 存储过程查询一张表中记录是否连续、重复并且取出对应的数据
- mysql查询连续时间数据——无数据补0
- SQL查询案例:利用笛卡尔积寻找连续日期中残缺的数据
- 查询第n条到第m条数据的sqlserver语句(其主键已经不再连续)
- SQL查询案例:寻找连续日期中残缺的数据
- 存储过程查询一张表中记录是否连续、重复并且取出对应的数据
- MS SQL server 2005中查询某张表从30-40条数据,但主键ID不是连续的
- 查询连续7天的数据sql问题
- 查询表里某个字段10-30之间的数据且ID不是连续的
- MS SQL server 2005中查询某张表从30-40条数据,但主键ID不是连续的
- 【MySQL】查询前7天的数据统计(解决日期不连续问题)
- SQL查询案例:寻找连续日期中残缺的数据_笛卡尔乘积
- 连续区间(数据岛)查询
- 【暑假】[实用数据结构]动态连续和查询问题
- 面试时的一道SQL题(查询第30行至40行的数据(其中不可根据id来查,因为id并不一定连续))
- 【暑假】[实用数据结构]动态连续和查询问题
- mysql 从某 id 开始,连续查询 10 条数据
- 根据日期的前一天后一天的改变查询数据
- 防止查询数据返回数据行为零引起的逻辑判断重复或抛出异常
- START WITH CONNECT BY PRIOR子句实现递归查询,主要用于查询数据中的树型结构关系[父子关系]