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 Combine_Two_Tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select FirstName, LastName, City, State
from Person left join Address
on Person.PersonId = Address.PersonId ;
8 changes: 8 additions & 0 deletions Customers_with_Strictly_increasing_Purchases.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;
5 changes: 5 additions & 0 deletions Game_Play_Analysis _II.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT A1.player_id, A1.device_id
FROM Activity A1
WHERE (A1.player_id, A1.event_date) IN (
SELECT A2.player_id, MIN(A2.event_date)
FROM Activity A2 GROUP BY A2.player_id );
3 changes: 3 additions & 0 deletions Game_Play_Analysis _III.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT A.player_id, A.event_date,
SUM(A.games_played) OVER ( PARTITION BY A.player_id ORDER BY A.event_date ) AS games_played_so_far
FROM Activity A;
3 changes: 3 additions & 0 deletions Shortest_Distance_in_a_Plane.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Write your MySQL query statement below
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 ON (p1.x <= p2.x AND p1.y < p2.y) OR (p1.x <= p2.x AND p1.y > p2.y) OR (p1.x < p2.x AND p1.y = p2.y) ;