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
12 changes: 12 additions & 0 deletions 1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

WITH cte AS (
SELECT
player_id AS p,
MIN(event_date) AS e
FROM Activity
GROUP BY player_id
)
SELECT a.player_id, a.device_id
FROM Activity a
JOIN cte
ON a.player_id = cte.p AND a.event_date = cte.e;
4 changes: 4 additions & 0 deletions 2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
player_id, event_date ,
SUM(games_played) OVER (PARTITION BY player_id order by event_date) AS games_played_so_far
FROM Activity;
4 changes: 4 additions & 0 deletions 3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select round(sqrt(min(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2))),2) as shortest
from Point2D p1
join Point2d p2
where p1.x!=p2.x or p2.y!=p1.y
5 changes: 5 additions & 0 deletions 4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
select p.firstname,p.lastname,
a.city, a.state
from Person p
left join Address a
on p.personId=a.personId
13 changes: 13 additions & 0 deletions 5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
with cte as (select customer_id, YEAR(order_date) as yr, sum(price) as price
from Orders
group by customer_id,yr
order by customer_id, yr
)

select c1.customer_id
from cte c1
left join cte c2
on c1.customer_id = c2.customer_id
and c1.yr+1=c2.yr and c1.price<c2.price
group by c1.customer_id
having count(*) - count( c2.customer_id) =1