diff --git a/11.sql b/11.sql new file mode 100644 index 0000000..a70a2a9 --- /dev/null +++ b/11.sql @@ -0,0 +1,18 @@ + +with cte as ( +select first_player as "p", first_score as s +from Matches +union all +select second_player as "p", second_score as s +from Matches +), +cte2 as( +select p1.player_id, p1.group_id, sum(s) as total +from cte +join Players p1 +on p1.player_id=cte.p +group by p1.player_id +order by total desc, p1.player_id asc) +select cte2.group_id as GROUP_ID, cte2.player_id as PLAYER_ID +from cte2 +group by group_id \ No newline at end of file diff --git a/2.sql b/2.sql new file mode 100644 index 0000000..97e6fd1 --- /dev/null +++ b/2.sql @@ -0,0 +1,17 @@ +with c as ( +select o.item_id,o.seller_id, i.item_brand,RANK() OVER (PARTITION BY seller_id ORDER BY order_date ASC) AS rnk +from Orders o +join items i +on o.item_id=i.item_id +), +c2 as (select c.item_brand,c.seller_id +from c +where rnk=2) +select u.user_id as seller_id, +case +when u.favorite_brand=c2.item_brand then 'yes' +else 'no' +end as 2nd_item_fav_brand +from users u +left join c2 +on u.user_id=c2.seller_id \ No newline at end of file