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
7 changes: 7 additions & 0 deletions CombineTwoTables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'''
4 Problem 4 : Combine Two Tables (https://leetcode.com/problems/combine-two-tables/)
'''

SELECT firstName, lastName, city, state
FROM Person
LEFT JOIN Address ON Address.personId = Person.personId
15 changes: 15 additions & 0 deletions CustomersWithStrictlyIncreasingPurchases.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'''
5 Problem 5 : Customers with Strictly Increasing Purchases (https://leetcode.com/problems/customers-with-strictly-increasing-purchases/)
'''

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

1 Problem 1 : Game Play Analysis II (https://leetcode.com/problems/game-play-analysis-ii/)

'''

SELECT player_id, device_id
FROM Activity
WHERE (player_id, event_date) IN (
SELECT player_id, MIN(event_date)
FROM Activity
GROUP BY player_id
)
6 changes: 6 additions & 0 deletions GamePlayAnalysisIII.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'''
2 Problem 2 : Game Play Analysis III (https://leetcode.com/problems/game-play-analysis-iii/)
'''

SELECT player_id, event_date, SUM(games_played) OVER (PARTITION BY player_id ORDER BY event_date) AS 'games_played_so_far'
FROM Activity
7 changes: 7 additions & 0 deletions ShortestDistanceInAPlane.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'''
3 Problem 3 : Shortest Distance in a Plane (https://leetcode.com/problems/shortest-distance-in-a-plane/)
'''

SELECT ROUND(SQRT(MIN(POWER(p1.x - p2.x, 2) + POWER(p1.y - p2.y, 2))), 2) AS shortest
FROM Point2D p1, Point2D p2
WHERE (p1.x, p1.y) <> (p2.x, p2.y)