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
5 changes: 5 additions & 0 deletions CustomersWho.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

select customer_id
from customer
group by customer_id
having count(distinct product_key)=(select count(product_key) from product);
19 changes: 19 additions & 0 deletions ProductAnalysis.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

-- Solution 1

select product_id, year as first_year, quantity, price
from (
select s.product_id, s.year, s.quantity, s.price,
DENSE_RANK() over (partition by product_id order by year) as rnk
from sales s
) ranked
where rnk = 1;

-- Solution 2

select s.product_id,newtab.first_year,s.quantity,s.price
from (select product_id, min(year) as first_year
from sales
group by product_id) as newtab
join sales s
on newtab.product_id=s.product_id and newtab.first_year=s.year;
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# Mock_SQL2
# Mock_SQL2