从 Customer 表中查询购买了 Product 表中所有产品的客户的 id
这道题关键点在于对每个顾客所购买的东西进行检索,即用count(distinct product_key)查出每个顾客购买的种类数,然后对应商品列表中有多少种类数。
SELECT customer_id
FROM customer
GROUP BY customer_id
HAVING COUNT(DISTINCT product_key) =
(SELECT COUNT(DISTINCT product_key) FROM product)