K otázce:get a list of customers who bought both A and B
SELECT CustomerID
FROM CustomerList
WHERE ProductID IN ('A', 'B')
GROUP BY CustomerID
HAVING COUNT(*) = 2
pokud nebyla u ProductID
vynucena jedinečnost pro každé CustomerID
, DISTINCT
klíčové slovo je povinné,
SELECT CustomerID
FROM CustomerList
WHERE ProductID IN ('A', 'B')
GROUP BY CustomerID
HAVING COUNT(DISTINCT ProductID ) = 2
U druhé otázky "..A a C a D, ale ne B a E a F"
SELECT CustomerID
FROM CustomerList
WHERE ProductID IN ('A', 'C', 'D')
GROUP BY CustomerID
HAVING COUNT(*) = 3 AND
CustomerID NOT IN
(
SELECT CustomerID
FROM CustomerList
WHERE ProductID IN ('B','E','F')
)