求一句SQL语句。(急)
表中的数据如下:字段1 字段2
AAA 111
AAA 222
AAA 333
BBB 111
BBB 222
CCC 111
CCC 222
DDD 111
DDD 222
DDD 333
我要找出
每个字母组中没有333的记录
查出的结果是:
字段1
BBB
CCC
请各位高手帮帮忙,很急!
create table shiyan(col1 char(3),col2 int)
insert into shiyan select 'AAA',111
union select 'AAA',222
union select 'AAA',333
union select 'BBB',111
union select 'BBB',222
union select 'CCC',111
union select 'CCC',222
union select 'DDD',111
union select 'DDD',222
union select 'DDD',333
select distinct col1 from shiyan s1 where not exists(select 1 from shiyan s2 where s1.col1=s2.col1 and s2.col2=333)
select distinct col1 from shiyan s1 where col1 not in (select col1 from shiyan where col2=333)