读书人

Sql中怎的跳跃读取行

发布时间: 2013-08-04 18:26:16 作者: rapoo

Sql中怎样跳跃读取行
表A:
ID Text
1 8888
2 2222
3 11111
4 098023
5 929829842
6 9908082083
7 8777923
8 89789
9 897982932
........

现在我想得到 id=1 id=4 id=7 ....
得到每个ID+3的数据。。请指教

SQL
[解决办法]

if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (ID int,Text nvarchar(20))
insert into [TB]
select 1,'8888' union all
select 2,'2222' union all
select 3,'11111' union all
select 4,'098023' union all
select 5,'929829842' union all
select 6,'9908082083' union all
select 7,'8777923' union all
select 8,'89789' union all
select 9,'897982932'

select * from [TB]

SELECT * FROM TB WHERE id%3=1

/*
IDText
18888
4098023
78777923*/

读书人网 >SQL Server

热点推荐