LeetCode 512: Game Play Analysis II [SQL]

  Рет қаралды 6,269

Frederik Müller

Frederik Müller

Күн бұрын

Пікірлер: 17
@mickyman753
@mickyman753 2 жыл бұрын
select player_id, device_id from Activity where (player_id, event_date) in (select player_id, min(event_date) from Activity group by player_id);
@rajatchopra1411
@rajatchopra1411 2 жыл бұрын
not free to solve :(
@hsrboys9993
@hsrboys9993 3 жыл бұрын
Great explanation using the window functions
@ManishAshtikar-jv5tq
@ManishAshtikar-jv5tq Жыл бұрын
@Freferikmuller Can you solve this in SQL Server?
@kirthikka952
@kirthikka952 2 жыл бұрын
select player_id, device_id from Activity group by player_id is this correct?
@maheshodedra8609
@maheshodedra8609 3 жыл бұрын
Hey Fredrik, Thanks for the great video, Can't we use below query ? select player_id,device_id from Activity where (player_id,event_date) in (select player_id,min(event_date) as event_date from Activity group by player_id) Looking forward to your response. Thanks
@frederikmuller
@frederikmuller 3 жыл бұрын
Yes, that's a viable solution and probably all that's needed for that question. I got into the habit of using window functions for that question type because it's nice to have a flexible solution for some of these and change up the rank or row number filter. That being said, your solution is similar to the first in this video, it's just using WHERE IN instead of a join which essentially does the same thing in this case.
@dhartishkhatri6240
@dhartishkhatri6240 3 жыл бұрын
Great video thank you for second solution, it can be used in many different ways.
@souravmoha2224
@souravmoha2224 2 жыл бұрын
Quick Question Fredrik, How this query run in your system, I believe we cant use other columns apart from aggregate functions in select clause , if we are using group by , we can only select the columns we are grouping by, Let me know if i am making any mistake here select player_id, min(event_dt),device_id from activity group by player_id Error while compiling statement: FAILED: SemanticException [Error 10025]: Line 2:32 Expression not in GROUP BY key 'device_id'
@frederikmuller
@frederikmuller 2 жыл бұрын
I’m using MySQL in this video which doesn’t have this restriction. You would have to rearrange the query in another SQL dialect.
@vickyzhang820
@vickyzhang820 3 жыл бұрын
Why we need to add "lookup" at the end of syntax?
@frederikmuller
@frederikmuller 3 жыл бұрын
it's just a name for the table created by the subquery, you can choose any name you want
@anushreepatil4811
@anushreepatil4811 3 жыл бұрын
What's wrong with this query? Select player_id, Device_id from activity group by player_id having min(event_date)
@frederikmuller
@frederikmuller 3 жыл бұрын
the having clause
@watchlistsclips3196
@watchlistsclips3196 3 жыл бұрын
@@frederikmuller What's the problem if we have having clause
@robinsharma9807
@robinsharma9807 3 жыл бұрын
Hi Sir, can you please explain why this would be wrong select player_id, device_id,min(event_date) as event_date from activity group by player_id, device_id
@imdeepu7855
@imdeepu7855 2 жыл бұрын
Editor accepts only the expected output, which are player_id and device_id as end columns of output and group by device_id won't be work here. As per the table data, device_type may change in each player itself. so can't be take device_id on group by field.
LeetCode 534: Game Play Analysis III [SQL]
8:44
Frederik Müller
Рет қаралды 6 М.
LeetCode 1581: Customer Who Visited but Did Not Make Any Transactions [SQL]
11:52
When mom gets home, but you're in rollerblades.
00:40
Daniel LaBelle
Рет қаралды 70 МЛН
Family Love #funny #sigma
00:16
CRAZY GREAPA
Рет қаралды 4,9 МЛН
Когда отец одевает ребёнка @JaySharon
00:16
История одного вокалиста
Рет қаралды 16 МЛН
Cool Parenting Gadget Against Mosquitos! 🦟👶 #gen
00:21
TheSoul Music Family
Рет қаралды 33 МЛН
Learn SQL + Database Concepts in 20 Minutes
24:34
Chandoo
Рет қаралды 70 М.
LeetCode 511: Game Play Analysis I [SQL]
3:15
Frederik Müller
Рет қаралды 7 М.
Solving SQL Interview Queries | Tricky SQL Interview Queries
37:22
Go Has Exceptions??
16:58
ThePrimeTime
Рет қаралды 71 М.
When mom gets home, but you're in rollerblades.
00:40
Daniel LaBelle
Рет қаралды 70 МЛН