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
9 changes: 9 additions & 0 deletions Market Analysis II .sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
with cte as (select order_date,item_brand , seller_id , rank() over ( partition by o.seller_id order by o.order_date) as 'rnk'
from orders o join items i on o.item_id=i.item_id )

, cte2 as ( select * from cte where rnk=2)
select user_id as 'seller_id', case
when rnk=2 and item_brand = favorite_brand then 'yes'
else 'no'
end as '2nd_item_fav_brand'
from users left join cte2 on cte2.seller_id=users.user_id
11 changes: 11 additions & 0 deletions Tournament Winners.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
with cte1 as (select player_id,sum(total) as final_score
from (select first_player as player_id, first_score as total from Matches
union all
select second_player as player_id ,second_score as total from Matches) as cte
group by player_id),

cte2 as(select p.player_id, p.group_id , rank () over( partition by p.group_id order by ifnull(c.final_score,0) desc, p.player_id ) as rnk
from players p left join cte1 c
on p.player_id=c.player_id )

select group_id, player_id from cte2 where rnk =1