diff --git a/Combine_Two_Tables.sql b/Combine_Two_Tables.sql new file mode 100644 index 0000000..d802252 --- /dev/null +++ b/Combine_Two_Tables.sql @@ -0,0 +1,2 @@ +SELECT p.firstName, p.lastName, a.city, a.state FROM Person p +LEFT JOIN Address a ON p.personId = a.personId; diff --git a/Game_play_analysis_III.sql b/Game_play_analysis_III.sql new file mode 100644 index 0000000..897f24a --- /dev/null +++ b/Game_play_analysis_III.sql @@ -0,0 +1,2 @@ +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/customers_with_strictly_increasing.sql b/customers_with_strictly_increasing.sql new file mode 100644 index 0000000..dd105a1 --- /dev/null +++ b/customers_with_strictly_increasing.sql @@ -0,0 +1,8 @@ +WITH CTE AS ( +SELECT customer_id, substr(order_date,1,4) as o_date, sum(price) as total FROM Orders +Group by substr(order_date,1,4), customer_id +) + +SELECT a.customer_id FROM CTE a LEFT JOIN CTE b ON a.customer_id = b.customer_id and a.o_date + 1 = b.o_date and a.total < b.total +Group by a.customer_id +Having count(distinct b.o_date) = max(a.o_date) - min(a.o_date) diff --git a/gmae_play_analysis_ii.sql b/gmae_play_analysis_ii.sql new file mode 100644 index 0000000..84b3f03 --- /dev/null +++ b/gmae_play_analysis_ii.sql @@ -0,0 +1,2 @@ +SELECT DISTINCT player_id, FIRST_VALUE(device_id) OVER(PARTITION BY player_id +ORDER BY event_date) AS device_id 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..e2ab506 --- /dev/null +++ b/shortest_distance_in_a_plane.sql @@ -0,0 +1,2 @@ +SELECT ROUND(SQRT(MIN(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;