1

我有一张桌子:

num type flag
--- ---- ----
11   A    1
12   A    1
13   A    1
14   A    1
15   A    1

12   B    2
13   B    2

我将如何编写查询以获得以下结果:

num type flag
--- ---- ----
11   A     1
14   A     1
15   A     1
4

2 回答 2

2
select num
from your_table
where num not in
(
  select num
  from your_table
  where type = 'B'
)
于 2013-08-13T08:58:10.820 回答
0

尝试not exists如下使用

select * 
from tab  t
where t.type = 'A'
and not exists 
(
  select 1
  from tab t1
  where t1.type = 'B'
  and t1.num=t.num

)
于 2013-08-13T08:57:45.373 回答