diff --git a/Customers Who Bought All Products b/Customers Who Bought All Products new file mode 100644 index 0000000..48137fd --- /dev/null +++ b/Customers Who Bought All Products @@ -0,0 +1,2 @@ + +select distinct(c.customer_id) from customer c right join product p on c.product_key=p.product_key group by c.customer_id having count( distinct p.product_key) = (select count(distinct(product_key)) from product) diff --git a/Sales Analysis III b/Sales Analysis III new file mode 100644 index 0000000..d09806d --- /dev/null +++ b/Sales Analysis III @@ -0,0 +1,16 @@ +WITH cte AS ( + SELECT + product_id, + year, + quantity, + price, + RANK() OVER (PARTITION BY product_id ORDER BY year ASC) AS rnk + FROM Sales +) +SELECT + product_id, + year AS first_year, + quantity, + price +FROM cte +WHERE rnk = 1;