From 5b7059ee7749eeec9841f46e2edd0833525faa03 Mon Sep 17 00:00:00 2001 From: Feminto Date: Sun, 1 Jun 2025 17:55:23 -0700 Subject: [PATCH] Adding solution to the mock interview question --- customer_bought_all_products | 6 ++++++ product_sales_analysis_3 | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 customer_bought_all_products create mode 100644 product_sales_analysis_3 diff --git a/customer_bought_all_products b/customer_bought_all_products new file mode 100644 index 0000000..fee03e0 --- /dev/null +++ b/customer_bought_all_products @@ -0,0 +1,6 @@ +SELECT customer_id +FROM customer c +JOIN product p +ON c.product_key = p.product_key +GROUP BY 1 +HAVING COUNT(DISTINCT p.product_key) = (SELECT COUNT(*) FROM product); \ No newline at end of file diff --git a/product_sales_analysis_3 b/product_sales_analysis_3 new file mode 100644 index 0000000..4e3e4d5 --- /dev/null +++ b/product_sales_analysis_3 @@ -0,0 +1,14 @@ +WITH cte AS( + SELECT product_id, + MIN(year) AS min_year + FROM sales + GROUP BY 1 +) +SELECT s.product_id, + s.year AS first_year, + s.quantity, + s.price +FROM sales s +JOIN cte c +ON c.product_id = s.product_id +AND c.min_year = s.year; \ No newline at end of file