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

提取数据段有关问题(急)

2012-03-11 
提取数据段问题(急啊)表A为:Message(字段名)djOKdjflkieopoewwwxYESm3tOKwesffjjkkYESjfkdj要查询出从OK到

提取数据段问题(急啊)
表A为:
Message(字段名)
dj
OK
djflk
ieo
po
ew
ww
x
YES
m
3
t
OK
we
sff
jj
kk
YES
jfkdj
要查询出从OK到YES的所有行(注:OK到YES的数据段有多段)
请问SQL语句怎么写????

[解决办法]
--测试数据
create table a(Message varchar(20))
insert into a select 'dj ' union all
select 'OK ' union all
select 'djflk ' union all
select 'ieo ' union all
select 'po ' union all
select 'ew ' union all
select 'ww ' union all
select 'x ' union all
select 'YES ' union all
select 'm ' union all
select '3 ' union all
select 't ' union all
select 'OK ' union all
select 'we ' union all
select 'sff ' union all
select 'jj ' union all
select 'kk ' union all
select 'YES ' union all
select 'jfkdj '

--查询
select id=identity(int,1,1),Message into # from a

select message from (select Message,(select count(1) from # where message= 'OK ' and id <=t.id)-(select count(1) from # where message= 'YES ' and id <t.id) as tp from # t) tt where tp=1

--删除临时表
drop table #


--结果
OK
djflk
ieo
po
ew
ww
x
YES
OK
we
sff
jj
kk
YES

热点排行