diff --git a/Problem1_GamePlay2.sql b/Problem1_GamePlay2.sql new file mode 100644 index 0000000..5147da6 --- /dev/null +++ b/Problem1_GamePlay2.sql @@ -0,0 +1,4 @@ +# Write your MySQL query statement below +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/Problem2_GamePlay3.sql b/Problem2_GamePlay3.sql new file mode 100644 index 0000000..746db7c --- /dev/null +++ b/Problem2_GamePlay3.sql @@ -0,0 +1,5 @@ +# Write your MySQL query statement below +select +player_id,event_date, +sum(games_played) over(partition by player_id order by event_Date) as games_played_so_far +from activity; diff --git a/Problem3_shortestDist.sql b/Problem3_shortestDist.sql new file mode 100644 index 0000000..e31e977 --- /dev/null +++ b/Problem3_shortestDist.sql @@ -0,0 +1,6 @@ +# Write your MySQL query statement below +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 diff --git a/Problem4_Combine2Tables.sql b/Problem4_Combine2Tables.sql new file mode 100644 index 0000000..2244fea --- /dev/null +++ b/Problem4_Combine2Tables.sql @@ -0,0 +1,4 @@ +# Write your MySQL query statement below +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/Problem5_CustomersWithIncreasingPurchase.sql b/Problem5_CustomersWithIncreasingPurchase.sql new file mode 100644 index 0000000..cb8cc4c --- /dev/null +++ b/Problem5_CustomersWithIncreasingPurchase.sql @@ -0,0 +1,14 @@ +# Write your MySQL query statement below +with cte as ( +select distinct customer_id,year(order_date) as year, +sum(price) over(partition by customer_id,year(order_date)) as price +from Orders order by customer_id,year) + +select +distinct 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;