From 4d7b9df867b9c32b6db6bbc9082582ad76e6dd77 Mon Sep 17 00:00:00 2001 From: tejas274 Date: Fri, 30 May 2025 18:46:19 -0400 Subject: [PATCH 1/5] problem 1 added --- problem1-512-game-play-analysis2.sql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 problem1-512-game-play-analysis2.sql diff --git a/problem1-512-game-play-analysis2.sql b/problem1-512-game-play-analysis2.sql new file mode 100644 index 0000000..61c3162 --- /dev/null +++ b/problem1-512-game-play-analysis2.sql @@ -0,0 +1,18 @@ +with row_num_based_user_activity as ( + select + player_id, + device_id, + row_number() over ( + partition by player_id + order by event_date + ) as rnk + from activity +) + +select + player_id, + device_id +from + row_num_based_user_activity +where + rnk = 1 \ No newline at end of file From 57377a37003cfb21313ac1833e8943504d744fd2 Mon Sep 17 00:00:00 2001 From: tejas274 Date: Sun, 1 Jun 2025 07:14:53 -0400 Subject: [PATCH 2/5] adhoc: problem 2 added --- problem2-534-game-play-analysis3.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 problem2-534-game-play-analysis3.sql diff --git a/problem2-534-game-play-analysis3.sql b/problem2-534-game-play-analysis3.sql new file mode 100644 index 0000000..e743b0a --- /dev/null +++ b/problem2-534-game-play-analysis3.sql @@ -0,0 +1,12 @@ +select + player_id, + event_date, + sum(games_played) + over ( + partition by player_id + order by event_date + ) + as games_played_so_far +from + activity +order by player_id, event_date \ No newline at end of file From e9c49cea0d7037a972f0bd5112d8e2b38b50e716 Mon Sep 17 00:00:00 2001 From: tejas274 Date: Sun, 1 Jun 2025 08:14:11 -0400 Subject: [PATCH 3/5] problem 4 added --- problem4-175-combine-two-tables.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 problem4-175-combine-two-tables.sql diff --git a/problem4-175-combine-two-tables.sql b/problem4-175-combine-two-tables.sql new file mode 100644 index 0000000..1b3e4fa --- /dev/null +++ b/problem4-175-combine-two-tables.sql @@ -0,0 +1,11 @@ +select + FIRSTNAME, + LASTNAME, + CITY, + STATE +from + PERSON +left join + ADDRESS + on + PERSON.PERSONID = ADDRESS.PERSONID \ No newline at end of file From ce4f03d7a2559f9252c4ecbe7e3531fb5de64869 Mon Sep 17 00:00:00 2001 From: tejas274 Date: Tue, 3 Jun 2025 10:31:39 -0400 Subject: [PATCH 4/5] problem 3 added --- problem3-612-shortestt-distance-plane.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 problem3-612-shortestt-distance-plane.sql diff --git a/problem3-612-shortestt-distance-plane.sql b/problem3-612-shortestt-distance-plane.sql new file mode 100644 index 0000000..f688592 --- /dev/null +++ b/problem3-612-shortestt-distance-plane.sql @@ -0,0 +1,8 @@ +select + round(min(sqrt(power(p2.x - p1.x, 2) + power(p2.y - p1.y, 2))), 2) + as shortest +from + point2d as p1 +inner join + point2d as p2 + on (p1.x, p1.y) < (p2.x, p2.y) \ No newline at end of file From e49acb3711071d6cbb21a1ea56eca308c9b8dd48 Mon Sep 17 00:00:00 2001 From: tejas274 Date: Wed, 4 Jun 2025 13:01:32 -0400 Subject: [PATCH 5/5] problem 5 added --- ...tomers-with-strictly-increase-purchase.sql | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 problem5-2474-customers-with-strictly-increase-purchase.sql diff --git a/problem5-2474-customers-with-strictly-increase-purchase.sql b/problem5-2474-customers-with-strictly-increase-purchase.sql new file mode 100644 index 0000000..c91df3a --- /dev/null +++ b/problem5-2474-customers-with-strictly-increase-purchase.sql @@ -0,0 +1,25 @@ +with cte_customer_yoy_purchase as ( + select + customer_id, + YEAR(order_date) as order_year, + SUM(price) as total_price + from + orders + group by + customer_id, + YEAR(order_date) + order by + customer_id +) + +select cyoy.customer_id +from + cte_customer_yoy_purchase as cyoy +left join + cte_customer_yoy_purchase as cyoy1 + on + cyoy.customer_id = cyoy1.customer_id + and cyoy.order_year + 1 = cyoy1.order_year + and cyoy.total_price < cyoy1.total_price +group by cyoy.customer_id +having COUNT(*) - COUNT(cyoy1.customer_id) = 1