diff --git a/Combine_Two_Tables.txt b/Combine_Two_Tables.txt new file mode 100644 index 0000000..118ba94 --- /dev/null +++ b/Combine_Two_Tables.txt @@ -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_Purchase.txt b/Customers_with_Strictly_Increasing_Purchase.txt new file mode 100644 index 0000000..37eec2a --- /dev/null +++ b/Customers_with_Strictly_Increasing_Purchase.txt @@ -0,0 +1,4 @@ +WITH CTE AS ( + SELECT CUSTOMER_ID,YEAR(ORDER_DATE)AS YEARS ,SUM(PRICE) AS S_PRICE FROM ORDERS GROUP BY CUSTOMER_ID,YEARS ORDER BY CUSTOMER_ID,YEARS +) +SELECT C1.CUSTOMER_ID FROM CTE C1 LEFT JOIN CTE C2 ON C1.CUSTOMER_ID = C2.CUSTOMER_ID AND C1.YEARS + 1 = C2.YEARS AND C1.S_PRICE < C2.S_PRICE GROUP BY C1.CUSTOMER_ID HAVING COUNT(*) - COUNT(C2.CUSTOMER_ID) = 1; \ No newline at end of file diff --git a/Gameplay_Analysis_II.txt b/Gameplay_Analysis_II.txt new file mode 100644 index 0000000..b678e69 --- /dev/null +++ b/Gameplay_Analysis_II.txt @@ -0,0 +1 @@ +select Player_id, device_id from (select distinct player_id,rank() over (partition by player_id order by event_date) as rnk , device_id from activity) a where a.rnk = 1; \ No newline at end of file diff --git a/Gameplay_Analysis_III.txt b/Gameplay_Analysis_III.txt new file mode 100644 index 0000000..c15753c --- /dev/null +++ b/Gameplay_Analysis_III.txt @@ -0,0 +1,3 @@ +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_Between_two_Plane.txt b/Shortest_Distance_Between_two_Plane.txt new file mode 100644 index 0000000..c84c5e6 --- /dev/null +++ b/Shortest_Distance_Between_two_Plane.txt @@ -0,0 +1,8 @@ +SELECT + ROUND(MIN(SQRT(POWER(p1.x - p2.x, 2) + POWER(p1.y - p2.y, 2))), 2) AS shortest +FROM + Point2D p1 +JOIN + Point2D p2 +ON + p1.x != p2.x OR p1.y != p2.y;