From 59e94896f3dd1d076bcbb48a66639b5df87419af Mon Sep 17 00:00:00 2001 From: Dhruv Parashar Date: Mon, 9 Jun 2025 14:56:26 -0400 Subject: [PATCH] Done Sql6 --- Combine Two Tables.sql | 1 + Customers with Strictly Increasing Purchases.sql | 8 ++++++++ Game Play Analysis II.sql | 1 + Game Play Analysis III.sql | 1 + Shortest Distance in a Plane.sql | 1 + 5 files changed, 12 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..adbd739 --- /dev/null +++ b/Combine Two Tables.sql @@ -0,0 +1 @@ +SELECT p.firstName, p.lastName, a.city, a.state FROM Person p LEFT JOIN Address a ON p.personID = a.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..7184a45 --- /dev/null +++ b/Game Play Analysis II.sql @@ -0,0 +1 @@ +SELECT a.player_id, a.device_id FROM Activity a WHERE a.event_date IN (SELECT MIN(b.event_date) FROM Activity b WHERE a.player_id = b.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..d203e16 --- /dev/null +++ b/Game Play Analysis III.sql @@ -0,0 +1 @@ +SELECT player_id, event_date, SUM(games_played) OVER (PARTITION BY player_id ORDER BY event_date) AS 'games_played_so_far' FROM Activity \ 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..18b20da --- /dev/null +++ b/Shortest Distance in a Plane.sql @@ -0,0 +1 @@ +SELECT ROUND(MIN(SQRT(POW(p2.x - p1.x,2) + POW(p2.y - p1.y, 2))), 2) AS 'shortest' FROM Point2d p1 INNER JOIN Point2d p2 ON p1.x != p2.x OR p1.y != p2.y \ No newline at end of file