首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

这样的 select 语句如何写

2012-01-06 
这样的 select 语句怎么写?我要搜索从第10条记录开始的3条记录,用select语句怎么写?因为我已经selecttop9I

这样的 select 语句怎么写?
我要搜索   从第10条记录开始的3条记录,   用   select   语句怎么写?
因为我已经   select   top   9   ID   from   mydatabase   了,现在要   从第10到12条记录。

[解决办法]
if object_id( 'ta ')> 0 drop table ta

create table ta(A int identity(1,1),B varchar(8))

insert into ta
select 'A1 ' union all select 'A2 ' union all select 'A3 ' union all select 'A4 '
union all select 'A5 ' union all select 'A6 ' union all select 'A7 ' union all select 'A8 '
union all select 'A9 ' union all select 'A10 ' union all select 'A11 ' union all select 'A12 '
union all select 'A13 ' union all select 'A14 ' union all select 'A15 ' union all select 'A16 '

select top 3 * from ta a where a.A not in(select top 9 A from ta B order by B.A) order by a.A

--***结果
/*
A B
----------- --------
10 A10
11 A11
12 A12
*/

drop table ta

热点排行
Bad Request.