我的数据如下:
group_id | meta_key | meta_value
----------------------------------------
33 | has_foo | definitely_has_foo
33 | is_bar | might_be_bar
33 | a_key | a_value
65 | has_foo | probably
86 | something| something_else
我想选择不的所有group_id
meta_key
名为has_foo
,在这种情况下为86
。有没有办法做到这一点?
答案 0 :(得分:3)
select group_id
from your_table
group by group_id
having sum(meta_key = 'has_foo') = 0
答案 1 :(得分:1)
SELECT group_id
FROM T
WHERE group_id NOT IN (SELECT group_id FROM T WHERE meta_key = 'has_foo')