当前位置: 代码迷 >> Delphi >> sql查询解决办法
  详细解决方案

sql查询解决办法

热度:357   发布时间:2013-02-25 00:00:00.0
sql查询
有一张表student 字段id,字段name

表student中有20条数据

要求:

查询不在前五条的前十五条数据数据,如何查?

------解决方案--------------------------------------------------------
select * from talbe where rownun > 15
------解决方案--------------------------------------------------------
SQL code
select top 15 * from student where id not in(select top 5 from student order by id) order by id
------解决方案--------------------------------------------------------
SQL code
--sql 2005select * from(select *,row_id=row_number() over(order by id) from student)awhere  row_id between 6 and 20
------解决方案--------------------------------------------------------
探讨
有一张表student 字段id,字段name

表student中有20条数据

要求:

查询不在前五条的前十五条数据数据,如何查?

------解决方案--------------------------------------------------------
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;
------解决方案--------------------------------------------------------
探讨
引用:
有一张表student 字段id,字段name

表student中有20条数据

要求:

查询不在前五条的前十五条数据数据,如何查?

只有20条.........

SQL code
select top 15 * from tb order by id desc

------解决方案--------------------------------------------------------
select top 15 * from student where id not in(select top 5 from student)
  相关解决方案