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 problem1-512-game-play-analysis2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
with row_num_based_user_activity as (
select
player_id,
device_id,
row_number() over (
partition by player_id
order by event_date
) as rnk
from activity
)

select
player_id,
device_id
from
row_num_based_user_activity
where
rnk = 1
12 changes: 12 additions & 0 deletions problem2-534-game-play-analysis3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
select
player_id,
event_date,
sum(games_played)
over (
partition by player_id
order by event_date
)
as games_played_so_far
from
activity
order by player_id, event_date
8 changes: 8 additions & 0 deletions problem3-612-shortestt-distance-plane.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
select
round(min(sqrt(power(p2.x - p1.x, 2) + power(p2.y - p1.y, 2))), 2)
as shortest
from
point2d as p1
inner join
point2d as p2
on (p1.x, p1.y) < (p2.x, p2.y)
11 changes: 11 additions & 0 deletions problem4-175-combine-two-tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
select
FIRSTNAME,
LASTNAME,
CITY,
STATE
from
PERSON
left join
ADDRESS
on
PERSON.PERSONID = ADDRESS.PERSONID
25 changes: 25 additions & 0 deletions problem5-2474-customers-with-strictly-increase-purchase.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
with cte_customer_yoy_purchase as (
select
customer_id,
YEAR(order_date) as order_year,
SUM(price) as total_price
from
orders
group by
customer_id,
YEAR(order_date)
order by
customer_id
)

select cyoy.customer_id
from
cte_customer_yoy_purchase as cyoy
left join
cte_customer_yoy_purchase as cyoy1
on
cyoy.customer_id = cyoy1.customer_id
and cyoy.order_year + 1 = cyoy1.order_year
and cyoy.total_price < cyoy1.total_price
group by cyoy.customer_id
having COUNT(*) - COUNT(cyoy1.customer_id) = 1