一张表的查询
create table test0518
(aID int primary key identity,
a varchar(10)
)
go
insert into test0518 (a) values ( 'x ')
insert into test0518 (a) values ( 'y ')
insert into test0518 (a) values ( 'z ')
insert into test0518 (a) values ( 'x ')
insert into test0518 (a) values ( 'y ')
insert into test0518 (a) values ( 'y ')
insert into test0518 (a) values ( 'z ')
原表
aID a
1 x
2 y
3 z
4 x
5 y
6 y
7 z
如何把x下面到下一个z之间的都填上x
如何把一下面到下一个z之间的都填上y
如何把一下面到下一个z之间的都填上z
结果
abcd
xx
yxy
zxyz
xx
yxy
yxy
zxyz
[解决办法]
这样吗?
select a,
case when a between 'x ' and 'z ' then 'x ' else ' ' end as b,
case when a> 'x ' and a <= 'z ' then 'y ' else ' ' end as c,
case when a= 'z ' then 'z ' else ' ' end as d
from test0518
[解决办法]
楼上的就可以实现
[解决办法]
select aid,a ,(case when aid <= (select top 1 aid from test0518 b where b.a= 'z ' and a.a> = 'x ' and b.aid-a.aid> =0) then b end),
(case when aid <= (select top 1 aid from test0518 b where b.a= 'z ' and a.a> = 'y ' and b.aid-a.aid> =0) then b end),
(case when aid <= (select top 1 aid from test0518 b where b.a= 'z ' and a.a> = 'z ' and b.aid-a.aid> =0) then b end)
from
test0518 a
[解决办法]
要是一列含有多的字母的话这要一个实现a-z排序的函数来实现了
[解决办法]
我没看懂题目