leetcode

Leetcode submissions
git clone git://git.laack.co/leetcode.git
Log | Files | Refs | README

customers-who-bought-all.sql (352B)


      1 --This gives a TLE but basically finds
      2 --all customers who have bought every product
      3 --at least one time using subqueries
      4 
      5 SELECT Customer.customer_id
      6 FROM Customer
      7 WHERE (
      8   SELECT COUNT(DISTINCT(C.product_key)) 
      9   FROM Customer AS C
     10   WHERE C.customer_id = Customer.customer_id
     11 ) = (
     12   SELECT COUNT(*) 
     13   FROM Product
     14 )
     15 GROUP BY Customer.customer_id