leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit ce2af72e838f135022bb054d1340a4f7e5c26be0
parent a2005ad7688f83194620b633cf07b729751d6705
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Mon, 10 Jul 2023 08:25:20 -0500

Completed customers who bought all products using sql

Diffstat:
Acustomers-who-bought-all-products/customers-who-bought-all.sql | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/customers-who-bought-all-products/customers-who-bought-all.sql b/customers-who-bought-all-products/customers-who-bought-all.sql @@ -0,0 +1,15 @@ +--This gives a TLE but basically finds +--all customers who have bought every product +--at least one time using subqueries + +SELECT Customer.customer_id +FROM Customer +WHERE ( + SELECT COUNT(DISTINCT(C.product_key)) + FROM Customer AS C + WHERE C.customer_id = Customer.customer_id +) = ( + SELECT COUNT(*) + FROM Product +) +GROUP BY Customer.customer_id