有一张表student 字段id,字段name
表student中有20条数据
要求:
查询不在前五条的前十五条数据数据,如何查?
------解决方案--------------------------------------------------------
select * from talbe where rownun > 15
------解决方案--------------------------------------------------------
select top 15 * from student where id
not in(select top 5 from student order by id) order by id
------解决方案--------------------------------------------------------
--sql 2005
select * from(select *,row_id=row_number() over(order by id) from student)a
where row_id between 6 and 20
------解决方案--------------------------------------------------------
只有20条.........
select top 15 * from tb order by id desc
------解决方案--------------------------------------------------------
select top 15 * from student order by id desc
www.hzyatong.cn
www.tuoye.net
------解决方案--------------------------------------------------------
针对数据库Mysql:
select * from student order by id asc limit 5,15;
针对数据库SQL SERVER 2000:
select top 15 * from student where id not in (select top 5 id from student);
针对SQL SERVER 2005:
select * from (
select row_number over(order by id asc) as row_num from student
) as a where a.row_num>5;
针对DB2:
select * from student where id not in (
select id from student fetch first 5 only
) fetch first 15 only;
------解决方案--------------------------------------------------------
经典,但太局限了,呵呵
------解决方案--------------------------------------------------------
select top 15 * from student where id not in(select top 5 from student)