select t.* from table_a t
where not exists(select 1 from table_a
where substring(file_a,1,1)=substring(t.file_a,1,1)
and substring(file_a,2,2)=substring(t.file_a,2,2)
and substring(file_a,7,3)=substring(t.file_a,7,3)
and substring(file_a,4,3)>substring(t.file_a,4,3))
and substring(t.file_a,2,2)='06'
select t.* from A表 t
where not exists(select 1 from A表
where left(字段a,3)= left(t.字段a,3)
and right(字段a,3)= right(t.字段a,3)
and substring(字段a,4,3) > substring(t.字段a,4,3))
--生成测试数据
create table A表(字段a varchar(10))
insert into A表 select 'N06001ccc'
insert into A表 select 'N06002ccc'
insert into A表 select 'N05010ccc'
insert into A表 select 'N05001ccc'
insert into A表 select 'N05011ccc'
insert into A表 select 'N04101ccc'
insert into A表 select 'N04001ccc'
insert into A表 select 'N04111ccc'
insert into A表 select 'N03001ccc'
insert into A表 select 'N03003ccc'
--执行查询处理
select
t.*
from
A表 t
where
substring(t.字段a,2,2) = '06'
and
not exists(select
1
from
A表
where
left(字段a,3) = left(t.字段a,3)
and
right(字段a,3) = right(t.字段a,3)
and
substring(字段a,4,3) > substring(t.字段a,4,3))
select * from 表 A
where not exists
(select 1 from 表 where
substring(字段,1,1)=substring(A.字段,1,1)
and substring(字段,2,2)=substring(A.字段,2,2)
and substring(字段,7,3)=substring(A.字段,7,3)
and substring(字段,4,3)>substring(A.字段,4,3)
)
--生成测试数据
create table A表(字段a varchar(10))
insert into A表 select 'N06001ccc'
insert into A表 select 'N06002ccc'
insert into A表 select 'N05010ccc'
insert into A表 select 'N05001ccc'
insert into A表 select 'N05011ccc'
insert into A表 select 'N04101ccc'
insert into A表 select 'N04001ccc'
insert into A表 select 'N04111ccc'
insert into A表 select 'N03001ccc'
insert into A表 select 'N03003ccc'
--执行查询处理
select
t.*
from
A表 t
where
not exists(select
1
from
A表
where
left(字段a,3) = left(t.字段a,3)
and
right(字段a,3) = right(t.字段a,3)
and
substring(字段a,4,3) > substring(t.字段a,4,3))
select
t.*
from
A表 t
where
not exists(select
1
from
A表
where
left(字段a,3) = left(t.字段a,3)
and
right(字段a,3) = right(t.字段a,3)
and
substring(字段a,4,3) > substring(t.字段a,4,3))