我需要一些代码方面的帮助
我有 2 个表,分别称为“stuff”和“something”,我有以下信息:
stuff something
+-------------+---------------------+ +-------------+---------------------+
| member_id | group_id | | group_id | some_id |
+-------------+---------------------+ +-------------+---------------------+
| 11 | aa | | aa | 7 |
| 11 | bb | | dd | 8 |
| 22 | bb | | bb | 9 |
| 11 | cc | +-------------+---------------------+
| 22 | cc |
| 33 | cc |
| 11 | dd |
+-------------+---------------------+
这个查询:
SELECT group_id
FROM stuff a
WHERE member_id IN (11) -- <<== list of member_id (can be 11,22 or 22,33 or 11,22,33)
AND
EXISTS
(
SELECT group_id
FROM stuff b
WHERE a.group_id = b.group_id
GROUP BY group_id
HAVING COUNT(*) = 1 -- <<== number of member_id
)
GROUP BY group_id
HAVING COUNT(*) = 1 -- <<== number of member_id
将返回aa
和dd
。
我的问题是:如果是,我该如何过滤结果some_id=7
?