diff --git a/Problem 2 Game Play Analysis 3.sql b/Problem 2 Game Play Analysis 3.sql new file mode 100644 index 0000000..a4ea3db --- /dev/null +++ b/Problem 2 Game Play Analysis 3.sql @@ -0,0 +1,2 @@ +# Write your MySQL query statement below +SELECT player_id, event_date, SUM(games_played) OVER (PARTITION BY player_id ORDER BY player_id, event_date ) AS 'games_played_so_far' FROM Activity \ No newline at end of file diff --git a/Problem 3 Shortest Distance in a Plane.sql b/Problem 3 Shortest Distance in a Plane.sql new file mode 100644 index 0000000..62d9bfc --- /dev/null +++ b/Problem 3 Shortest Distance in a Plane.sql @@ -0,0 +1,8 @@ +# 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 +INNER JOIN + Point2D p2 + WHERE p1.x<>p2.x OR p1.y <>p2.y; \ No newline at end of file diff --git a/Problem 4 Combile two tables.sql b/Problem 4 Combile two tables.sql new file mode 100644 index 0000000..9d40342 --- /dev/null +++ b/Problem 4 Combile two tables.sql @@ -0,0 +1,4 @@ +# Write your MySQL query statement below +SELECT firstName, lastName, city, state FROM Person +LEFT JOIN Address +ON Person.personId = Address.PersonId \ No newline at end of file diff --git a/Problem 5 Customers with strictly Increasing Purchases.sql b/Problem 5 Customers with strictly Increasing Purchases.sql new file mode 100644 index 0000000..4c6603e --- /dev/null +++ b/Problem 5 Customers with strictly Increasing Purchases.sql @@ -0,0 +1,14 @@ +# Write your MySQL query statement below +WITH CTE AS ( + SELECT customer_id, YEAR(order_date) AS Year, SUM(price) AS TotalPurchase + FROM orders + GROUP 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.TotalPurchase < c2.TotalPurchase +GROUP BY c1.customer_id +HAVING (COUNT(*)- COUNT(c2.customer_id))=1 \ No newline at end of file diff --git a/Problem1 Game Play Analysis 2.sql b/Problem1 Game Play Analysis 2.sql new file mode 100644 index 0000000..e7ad326 --- /dev/null +++ b/Problem1 Game Play Analysis 2.sql @@ -0,0 +1,6 @@ +# Write your MySQL query statement below +WITH CTE AS( + SELECT player_id, device_id, event_date, rank() OVER (PARTITION BY player_id ORDER BY event_date) AS 'rnk' FROM Activity) + + SELECT player_id, device_id FROM CTE + WHERE rnk = 1 \ No newline at end of file