2

我正在使用 T-SQL。

说如果我有以下

Value     Nbr
-----     ---
one       6
one       7
one       8
two       6
two       7
three     5
three     3
three     2

在上表中,我需要找出哪个组中没有 6。在这种情况下,它是 3,因为它没有 6。

这样做的最佳方法是什么?

我试过了:

      select Value from tbl1 
      where nbr <> 6
      group by Value 

但没有得到预期的结果。

4

1 回答 1

5
select distinct value
from tbl1
where value not in
(
    select distinct value
    from tbl1
    where nbr = 6
)
于 2012-12-21T02:11:30.857 回答