File tree Expand file tree Collapse file tree 2 files changed +78
-1
lines changed Expand file tree Collapse file tree 2 files changed +78
-1
lines changed Original file line number Diff line number Diff line change 11<!-- markdownlint-disable MD041 -->
22[ ![ eevveerryyddaayy release] ( https://img.shields.io/badge/eevveerryyddaayy-v1.3.0-blue.svg )] ( https://github.com/ggeerraarrdd/eevveerryyddaayy/ )
3- [ ![ Solved] ( https://img.shields.io/badge/solved-168 -green.svg )] ( #index )
3+ [ ![ Solved] ( https://img.shields.io/badge/solved-170 -green.svg )] ( #index )
44<!-- markdownlint-enable MD041 -->
55
66# SQL Everyday
@@ -203,6 +203,7 @@ Because this project necessitated a framework to enable consistent daily practic
203203| 167 | [ SQL Basics: Raise to the Power] ( https://www.codewars.com/kata/594a8f653b5b4e8f3d000035 ) | [ Solution] ( solutions/167_sql_basics_raise_to_the_power.md ) | Codewars | Easy | ` ^ ` or ` POW() ` |
204204| 168 | [ SQL Basics: Simple UNION ALL] ( https://www.codewars.com/kata/58112f8004adbbdb500004fe/sql ) | [ Solution] ( solutions/168_sql_basics_simple_union_all.md ) | Codewars | Medium | |
205205| 169 | [ NPV Queries] ( https://leetcode.com/problems/npv-queries/description/ ) | [ Solution] ( solutions/169_npv_queries.md ) | LeetCode | Easy | |
206+ | 170 | [ Game Play Analysis II] ( https://leetcode.com/problems/game-play-analysis-ii/description/ ) | [ Solution] ( solutions/170_game_play_analysis_ii.md ) | LeetCode | Easy | |
206207<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
207208<!-- - cSpell:enable --->
208209
Original file line number Diff line number Diff line change 1+ # SQL Everyday \# 170
2+
3+ ## Game Play Analysis II
4+
5+ Site: LeetCode\
6+ Difficulty per Site: Easy
7+
8+ ## Problem
9+
10+ Write a solution to report the * device* that is first logged in for each player.
11+
12+ Return the result table in * any order* . [[ Full Description] ( https://leetcode.com/problems/game-play-analysis-ii/description/ )]
13+
14+ ## Submitted Solution
15+
16+ ``` sql
17+ -- Submitted Solution
18+ WITH cte AS (
19+ SELECT
20+ player_id
21+ ,device_id
22+ ,ROW_NUMBER() OVER (PARTITION BY player_id ORDER BY event_date ASC ) AS rownum
23+ FROM Activity
24+ )
25+ SELECT
26+ player_id
27+ ,device_id
28+ FROM cte
29+ WHERE rownum = 1
30+ ;
31+ ```
32+
33+ ## Site Solution
34+
35+ ``` sql
36+ -- LeetCode Solution
37+ -- Solution 1: Subquery and multi-value use of the IN comparison operator
38+ SELECT
39+ A1 .player_id ,
40+ A1 .device_id
41+ FROM
42+ Activity A1
43+ WHERE
44+ (A1 .player_id , A1 .event_date ) IN (
45+ SELECT
46+ A2 .player_id ,
47+ MIN (A2 .event_date )
48+ FROM
49+ Activity A2
50+ GROUP BY
51+ A2 .player_id
52+ );
53+
54+ -- Site 2: Window functions
55+ SELECT DISTINCT
56+ A .player_id ,
57+ FIRST_VALUE(A .device_id ) OVER (
58+ PARTITION BY
59+ A .player_id
60+ ORDER BY
61+ A .event_date
62+ ) AS device_id
63+ FROM
64+ Activity A;
65+ ```
66+
67+ ## Notes
68+
69+ TBD
70+
71+ ## NB
72+
73+ TBD
74+
75+ Go to [ Index] ( ../?tab=readme-ov-file#index ) \
76+ Go to [ Overview] ( ../?tab=readme-ov-file )
You can’t perform that action at this time.
0 commit comments