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