6

假设我有一个这样的表:

| uid | group_id | 
-----------------
|   1 |     1    |
|   1 |     2    |
|   1 |     3    |
|   1 |     4    |
|   2 |     1    |
|   2 |     2    |
|   2 |     3    |
|   3 |     1    |
|   3 |     2    |
|   3 |     4    |
...

我怎样才能获得group_ids某些集合的通用集合uids

例如
对于 uid 1,2 :常见的 group_ids 是 1,2,3
对于 uid 1,2,3 :常见的 group_ids 是 1 和 2

4

1 回答 1

4

假设每个group_ID对每个都是唯一的uid,(否则你需要使用distinct

SELECT group_ID
FROM tableName
WHERE uid IN (1,2,3)
GROUP BY group_ID
HAVING COUNT(*) = 3
于 2012-12-22T14:21:32.403 回答