diff --git a/CombineTwoTables.sql b/CombineTwoTables.sql new file mode 100644 index 0000000..d8ea450 --- /dev/null +++ b/CombineTwoTables.sql @@ -0,0 +1 @@ +Select p.firstName,p.lastName,a.city,a.state from Person p Left join Address a on a.personId=p.personId; \ No newline at end of file diff --git a/CusStrictlyIncrease.sql b/CusStrictlyIncrease.sql new file mode 100644 index 0000000..281d619 --- /dev/null +++ b/CusStrictlyIncrease.sql @@ -0,0 +1,16 @@ +WITH CTE AS ( + SELECT + customer_id, + YEAR(order_date) AS year, + SUM(price) AS price + FROM orders + GROUP 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(c2.customer_id) = COUNT(c1.customer_id); diff --git a/GamePlayAnalysis2.sql b/GamePlayAnalysis2.sql new file mode 100644 index 0000000..160f393 --- /dev/null +++ b/GamePlayAnalysis2.sql @@ -0,0 +1,12 @@ +#Approach 1: +Select a.player_id, a.device_id as first_login from Activity a where a.event_date in (select min(b.event_date) From Activity b where a.player_id=b.player_id); + + +#Approach 2: +select player_id,first_value(device_id) over (partition by player_id order by event_date) as device_id from activity; + + + +#Approach 3: +select player_id,last_value(device_id) over (partition by player_id order by event_date desc range between unbounded preceding and unbounded following) as device_id from activity; + diff --git a/GamePlayAnalysis3.sql b/GamePlayAnalysis3.sql new file mode 100644 index 0000000..7e87363 --- /dev/null +++ b/GamePlayAnalysis3.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/ShortestDis.sql b/ShortestDis.sql new file mode 100644 index 0000000..c91712d --- /dev/null +++ b/ShortestDis.sql @@ -0,0 +1,18 @@ +#Approach 1: +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 and p1.y>p2.y) or (p1.x<=p2.x and p1.y>p2.y) or (p1.x