From ed48867d4f50181bf1b208b47eb4f2485765c5cb Mon Sep 17 00:00:00 2001 From: Sakshi Asati Date: Fri, 13 Jun 2025 19:41:14 -0600 Subject: [PATCH] Done SQL 6 --- Combine_Two_Tables.sql | 3 +++ Customers_with_Strictly_increasing_Purchases.sql | 8 ++++++++ Game_Play_Analysis _II.sql | 5 +++++ Game_Play_Analysis _III.sql | 3 +++ Shortest_Distance_in_a_Plane.sql | 3 +++ 5 files changed, 22 insertions(+) create mode 100644 Combine_Two_Tables.sql create mode 100644 Customers_with_Strictly_increasing_Purchases.sql create mode 100644 Game_Play_Analysis _II.sql create mode 100644 Game_Play_Analysis _III.sql create mode 100644 Shortest_Distance_in_a_Plane.sql diff --git a/Combine_Two_Tables.sql b/Combine_Two_Tables.sql new file mode 100644 index 0000000..2fff140 --- /dev/null +++ b/Combine_Two_Tables.sql @@ -0,0 +1,3 @@ +select FirstName, LastName, City, State +from Person left join Address +on Person.PersonId = Address.PersonId ; \ No newline at end of file diff --git a/Customers_with_Strictly_increasing_Purchases.sql b/Customers_with_Strictly_increasing_Purchases.sql new file mode 100644 index 0000000..86df84e --- /dev/null +++ b/Customers_with_Strictly_increasing_Purchases.sql @@ -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; \ No newline at end of file diff --git a/Game_Play_Analysis _II.sql b/Game_Play_Analysis _II.sql new file mode 100644 index 0000000..69100cb --- /dev/null +++ b/Game_Play_Analysis _II.sql @@ -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 ); \ No newline at end of file diff --git a/Game_Play_Analysis _III.sql b/Game_Play_Analysis _III.sql new file mode 100644 index 0000000..bda152a --- /dev/null +++ b/Game_Play_Analysis _III.sql @@ -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; \ No newline at end of file diff --git a/Shortest_Distance_in_a_Plane.sql b/Shortest_Distance_in_a_Plane.sql new file mode 100644 index 0000000..17d948c --- /dev/null +++ b/Shortest_Distance_in_a_Plane.sql @@ -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) ; \ No newline at end of file