Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions customer_bought_all_products
Original file line number Diff line number Diff line change
@@ -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);
14 changes: 14 additions & 0 deletions product_sales_analysis_3
Original file line number Diff line number Diff line change
@@ -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;