Skip to content
Open
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
34 changes: 34 additions & 0 deletions MockSQL3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 1159 Market Analysis II

# Write your MySQL query statement below
WITH CTE as (
select o.order_date,o.item_id,o.seller_id, i.item_brand, row_number() over(partition by seller_id order by order_date) as 'num' from Orders o right join Items i on o.item_id=i.item_id
)

select u.user_id, c.order_date,c.item_id, c.seller_id, c.item_brand, u.favorite_brand as 'f_b' from cte c right join Users u on c.seller_id = u.user_id where num =2;


# 1194 Tournament Winners


WITH CTE AS (
SELECT first_player AS id, first_score AS score FROM Matches
UNION ALL
SELECT second_player AS id, second_score AS score FROM Matches
),
C2 AS (
SELECT
c.id,
SUM(c.score) AS total_score,
p.group_id,
RANK() OVER (PARTITION BY p.group_id ORDER BY SUM(c.score) DESC, c.id ASC) AS rnk
FROM CTE c
JOIN Players p ON p.player_id = c.id
GROUP BY c.id, p.group_id
)
SELECT
group_id AS GROUP_ID,
MIN(id) AS PLAYER_ID
FROM C2
WHERE rnk = 1
GROUP BY group_id;