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
4 changes: 4 additions & 0 deletions CombineTwoTables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT p.firstname, p.lastname, a.city, a.state
FROM person p
LEFT JOIN address a
ON p.personId = a.personId;
18 changes: 18 additions & 0 deletions CustomersWithStrictlyIncreasingPurchases.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
WITH CTE AS (
SELECT customer_id,
YEAR(order_date) AS order_year,
SUM(price) AS total
FROM Orders
GROUP BY customer_id, YEAR(order_date)
),
Ranked AS (
SELECT customer_id,
order_year,
ROW_NUMBER() OVER(PARTITION BY customer_id ORDER BY order_year) AS rank_year,
DENSE_RANK() OVER(PARTITION BY customer_id ORDER BY total) AS rank_total
FROM CTE
)
SELECT customer_id
FROM Ranked
GROUP BY customer_id
HAVING COUNT(CASE WHEN rank_year = rank_total THEN 1 END) = MAX(order_year) - MIN(order_year) + 1;
7 changes: 7 additions & 0 deletions GamePlayAnalysis2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT a.player_id, a.device_id
FROM (
SELECT b.player_id, b.device_id, b.event_date,
RANK() OVER(PARTITION BY b.player_id ORDER BY b.event_date) AS 'rnk'
FROM Activity b
) a
WHERE a.rnk = 1;
3 changes: 3 additions & 0 deletions GamePlayAnalysis3.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;
4 changes: 4 additions & 0 deletions ShortestDistanceInAPlane.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT ROUND(SQRT(MIN(POW(p2.x - p1.x, 2) + POW(p2.y - p1.y, 2))), 2) AS 'shortest'
FROM Point2D p1
JOIN Point2D p2
ON NOT (p1.x = p2.x AND p1.y = p2.y);