日期:2014-05-17 浏览次数:20784 次
select * from tb as a
(
select * from tb where 标识='Y'
) as b
where and a.序号 like b.序号+'%'
CREATE TABLE test([阶层] int,[序号] varchar(50),[标志] varchar(2))
go
insert into test
select 1,'0010','' union all
select 2,'0010010','' union all
select 3,'0010010010','' union all
select 2,'00100020','Y' union all
select 3,'001000200010','' union all
select 4,'0010002000100010','' union all
select 5,'00100020001000100010','' union all
select 2,'00100030','' union all
select 3,'001000300010','' union all
select 4,'0010003000100010','Y' union all
select 5,'00100030001000100010',''
SELECT * FROM test as a,(SELECT [序号] FROM test WHERE [标志]='Y') as b
WHERE a.[序号] LIKE b.[序号]+'%' and a.[标志]<>'Y'
drop table test