字段A 字段B
A 结束
A 开始
A 开始
A 开始
A 开始
A 开始
B 开始
B 开始
B 开始
C 开始
C 开始
C 开始
C 开始语句需要把字段A对应的字段B中不包含 结束的对应的记录集提取出来,
结果如下:B 开始
B 开始
B 开始
C 开始
C 开始
C 开始
C 开始
A 结束
A 开始
A 开始
A 开始
A 开始
A 开始
B 开始
B 开始
B 开始
C 开始
C 开始
C 开始
C 开始语句需要把字段A对应的字段B中不包含 结束的对应的记录集提取出来,
结果如下:B 开始
B 开始
B 开始
C 开始
C 开始
C 开始
C 开始
--> 测试数据:[test]
if object_id('[test]') is not null drop table [test]
create table [test]([字段A] varchar(1),[字段B] varchar(4))
insert [test]
select 'A','结束' union all
select 'A','开始' union all
select 'A','开始' union all
select 'A','开始' union all
select 'A','开始' union all
select 'A','开始' union all
select 'B','开始' union all
select 'B','开始' union all
select 'B','开始' union all
select 'C','开始' union all
select 'C','开始' union all
select 'C','开始' union all
select 'C','开始'select * from test a
where not exists(select 1 from test b
where a.字段A=b.字段A and b.字段B='结束')
/*
字段A 字段B
B 开始
B 开始
B 开始
C 开始
C 开始
C 开始
C 开始
*/
from tb t
where not exists(select 1 from tb where a=t.a and b='结束')