diff --git a/Market Analysis II b/Market Analysis II new file mode 100644 index 0000000..8c4cd7b --- /dev/null +++ b/Market Analysis II @@ -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 diff --git a/Tournament Winners b/Tournament Winners new file mode 100644 index 0000000..9f6e856 --- /dev/null +++ b/Tournament Winners @@ -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;