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
18 changes: 18 additions & 0 deletions 11.sql
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions 2.sql
Original file line number Diff line number Diff line change
@@ -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