我有下表:
A | B | C
1 I as
2 E as
1 E sa
3 I as
2 I sa
3 I sa
4 E as
4 E ad
1 I as
2 D sd
3 D sa
OUTPUT表:
A | B | C
1 I as
2 E as
1 E sa
3 I as
3 I sa
4 E as
4 E ad
应选择所有那些在字段B中具有值E
的记录。如果字段B中记录I的相同记录(对于字段A和C),则不应选择它。如果A和B中的值没有值E
,则应选择包含字段I
的记录。
答案 0 :(得分:0)
我想我知道你在问什么:
select A, B, C
from myTable t1
where B='E'
or (B='I' and not exists (
select *
from myTable t2
where t2.A=t1.A
and t2.C=t1.C
and t2.B='E'
))