MySQL Query to find customers who have ordered two specific products

前端 未结 6 644
终归单人心
终归单人心 2021-01-14 07:21

I\'m having trouble coming up with a query that will find all customers who have purchased both PROD1 and PROD2.

Here\'s a pseudo-query that kind of looks like what

6条回答
  •  [愿得一人]
    2021-01-14 07:56

    SELECT userid
      FROM TRANSACTIONS
     WHERE product_id in ('prod1', 'prod2')
    GROUP BY userid
    HAVING COUNT(DISTINCT product_id) = 2
    

提交回复
热议问题