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
8 changes: 8 additions & 0 deletions 01-ProductSalesAnalysis-III.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Mock Interview Question 1: Product Sales Analysis III (https://leetcode.com/problems/product-sales-analysis-iii)

with cte as (select product_id, year, quantity, price,
dense_rank() over(partition by product_id order by year) as rnk
from sales)
select product_id, year as first_year, quantity, price
from cte
where rnk=1
23 changes: 23 additions & 0 deletions 02-CustomersWhoBoughtAllProducts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- Mock Interview Question 2: Customers Who Bought All Products https://leetcode.com/problems/customers-who-bought-all-products

-- solution 1

with
p_cte as(
select count(product_key) as tot_pdt
from product
),
c_cte as (
select customer_id, count(distinct product_key) as c_pdt
from customer group by customer_id
)
select customer_id
from p_cte, c_cte
where tot_pdt=c_pdt

-- solution 2

select customer_id
from customer
group by customer_id
having count(distinct product_key) = (select count(product_key) from product)