如何找到p_option_id为1和11的产品。
p_id p_option_id
100 1
100 2
100 3
101 1
101 2
101 11
101 12
这应该返回
p_id
101
答案 0 :(得分:7)
试试这个:
SELECT p_id
FROM tableA
WHERE p_option_id IN (1, 11)
GROUP BY p_id
HAVING COUNT(DISTINCT p_option_id) = 2;