您的位置:首页 > 其它

查询不连续的数据

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条数据。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: