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

select u.user_id as 'seller_id',
CASE
when a.item_brand = u.favorite_brand then 'yes'
else 'no'
END as '2nd_item_fav_brand' from ACTE a right join users u on a.seller_id=u.user_id
10 changes: 10 additions & 0 deletions Tournament Winners
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
with cte as(
select first_player as player_id, sum(first_score) as total from (select first_player, first_score from matches
union all
select second_player, second_score from matches) a group by first_player
) ,

acte as (select c.player_id, p.group_id, c.total , row_number() over (partition by p.group_id order by c.total desc ,c.player_id ASC) as rnk from cte c join players p on
c.player_id=p.player_id)

select group_id, player_id from acte where rnk=1;