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
3 changes: 3 additions & 0 deletions Problem1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT a.player_id, a.device_id
FROM activity a
where a.event_date IN (SELECT MIN(b.event_date) FROM activity b WHERE a.player_id = b.player_id)
3 changes: 3 additions & 0 deletions Problem2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT player_id, event_date, SUM(games_played)
OVER(PARTITION BY player_id ORDER BY event_date) AS 'games_played_so_far'
FROM activity
3 changes: 3 additions & 0 deletions Problem3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT ROUND(MIN(SQRT(pow(p2.x-p1.x,2) + pow(p2.y-p1.y,2))),2) as 'shortest' from
point2D p1 INNER JOIN point2D p2
ON (p1.x, p1.y) < (p2.x, p2.y);
1 change: 1 addition & 0 deletions Problem4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT p.firstName, p.lastName, a.city, a.state from Person p LEFT JOIN Address a ON p.personId = a.personId
8 changes: 8 additions & 0 deletions Problem5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
WITH CTE AS(
SELECT customer_id , YEAR(order_date) as 'year', SUM(price) as 'price' from orders GROUP BY year , customer_id
order by customer_id , year
)

SELECT c1.customer_id from CTE c1 LEFT JOIN CTE c2 ON c1.customer_id = c2.customer_id
AND c1.year + 1 = c2.year AND c1.price < c2.price GROUP BY c1.customer_id
HAVING COUNT(*) - COUNT(c2.customer_id) = 1;