From 2d1f320315d1600b3e127f370d726e0bec229f91 Mon Sep 17 00:00:00 2001 From: SukeshSrinivas <123338848+SukeshSrinivas@users.noreply.github.com> Date: Sun, 12 Jan 2025 03:44:22 -0600 Subject: [PATCH 1/2] Done --- Problem 2 Game Play Analysis 3.sql | 2 ++ Problem 3 Shortest Distance in a Plane.sql | 8 ++++++++ Problem 4 Combile two tables.sql | 4 ++++ ...Customers with strictly Increasing Purchases.sql | 13 +++++++++++++ Problem1 Game Play Analysis 2.sql | 6 ++++++ 5 files changed, 33 insertions(+) create mode 100644 Problem 2 Game Play Analysis 3.sql create mode 100644 Problem 3 Shortest Distance in a Plane.sql create mode 100644 Problem 4 Combile two tables.sql create mode 100644 Problem 5 Customers with strictly Increasing Purchases.sql create mode 100644 Problem1 Game Play Analysis 2.sql 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..4e7da46 --- /dev/null +++ b/Problem 5 Customers with strictly Increasing Purchases.sql @@ -0,0 +1,13 @@ +# 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 DISTINCT 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 +WHERE c2.customer_id IS NOT NULL; \ 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 From adc2344ffc5da0976ffcd81e6bcfec97dddd475d Mon Sep 17 00:00:00 2001 From: SukeshSrinivas <123338848+SukeshSrinivas@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:38:41 -0600 Subject: [PATCH 2/2] Done --- Problem 5 Customers with strictly Increasing Purchases.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Problem 5 Customers with strictly Increasing Purchases.sql b/Problem 5 Customers with strictly Increasing Purchases.sql index 4e7da46..4c6603e 100644 --- a/Problem 5 Customers with strictly Increasing Purchases.sql +++ b/Problem 5 Customers with strictly Increasing Purchases.sql @@ -4,10 +4,11 @@ WITH CTE AS ( FROM orders GROUP BY customer_id, Year ) -SELECT DISTINCT c1.customer_id +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 -WHERE c2.customer_id IS NOT NULL; \ No newline at end of file +GROUP BY c1.customer_id +HAVING (COUNT(*)- COUNT(c2.customer_id))=1 \ No newline at end of file