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