表:

ID | Value
-----------------
1 | red
1 | black

2 | green
2 | black

array('green','orange','black');

我需要获取结果ID: 2

有人可以救我一命吗?

===============>>#1 票数:3 已采纳

SELECT id
FROM table
WHERE value IN ('green', 'orange', 'black')
      AND id NOT IN (
          SELECT id
          FROM table
          WHERE value NOT IN ('green', 'orange', 'black'))

===============>>#2 票数:2

尝试:

SELECT id
FROM table
group by id
having sum(case when value IN ('green', 'orange', 'black') then 1 else 0 end) > 0
and sum(case when value NOT IN ('green', 'orange', 'black') then 1 else 0 end) = 0

  ask by Koralek M. translate from so

未解决问题?本站智能推荐: