LeetCode 1661: Average Time of Process per Machine [SQL]

  Рет қаралды 10,199

Frederik Müller

Frederik Müller

Күн бұрын

Пікірлер: 15
@ayeoh47
@ayeoh47 2 жыл бұрын
this one felt more challenging than the other easy questions, i didnt think to create a self join, this made the problem much easier to solve thank you
@frederikmuller
@frederikmuller 2 жыл бұрын
glad it helped!
@illiat3164
@illiat3164 10 ай бұрын
I solved it by using 2 additional CTEs and I still think using CTEs here is more cleaner and production like code: with start_activity_type as ( select machine_id, process_id, timestamp as start_timestamp from Activity where activity_type = 'start' ), end_activity_type as ( select machine_id, process_id, timestamp as end_timestamp from Activity where activity_type = 'end' )
@459B
@459B 3 жыл бұрын
my solution without using join: select machine_id, avg(case when activity_type='end' then timestamp end)-avg(case when activity_type='start' then timestamp end) as processing_time from Activity group by machine_id
@mickyman753
@mickyman753 2 жыл бұрын
that's intuitive , thanks for the solution
@UmaAndLak
@UmaAndLak 2 жыл бұрын
This was what i typed in MySQL. Another solution. select machine_id, round(avg (end_timestamp - start_timestamp),3) as processing_time from ( select machine_id, process_id, SUM(if(activity_type ='start', timestamp,null)) AS start_timestamp, SUM(if(activity_type ='end', timestamp,null)) AS end_timestamp from Activity group by machine_id, process_id ) as t group by machine_id
@ayeoh47
@ayeoh47 2 жыл бұрын
this is what i sumbitted, this was my solution
@ThinkBigToday
@ThinkBigToday 3 жыл бұрын
Excellent explanation. You’re the 🐐
@vijaysakthivel4966
@vijaysakthivel4966 Жыл бұрын
Thank you so much for this explanation. Really helpful.
@SB-ix7db
@SB-ix7db 11 ай бұрын
usage of subquery in this question, will increase the time complexity!
@temenoscom3498
@temenoscom3498 6 ай бұрын
great work, thanks.
@lonakshibhagat3116
@lonakshibhagat3116 3 жыл бұрын
Hi, can we use case when in this problem or not?
@sanaayakurup5453
@sanaayakurup5453 2 жыл бұрын
My Solution-select machine_id,AVG(diff) from (select machine_id,end_time-start_time as diff from (select machine_id,process_id, sum(if(activity_type='start',time,0)) as start_time, sum(if(activity_type='end',time,0)) as end_time from Activity group by machine_id,process_id) t1 )t2 group by machine_id
@partidaa98
@partidaa98 Жыл бұрын
As a beginner (and this being an "easy" LC problem), I think it would be very helpful if you could explain the reasoning for some of your decision making/thought process. Sometimes it feels like you just say and type what you are doing, but it isn't always intuitive to follow your logic (at least to a beginner like me). Great video though, very clear and concise overall.
@frederikmuller
@frederikmuller Жыл бұрын
That’s good feedback, thank you!
LeetCode 577: Employee Bonus [SQL]
11:16
Frederik Müller
Рет қаралды 3,5 М.
LeetCode 1251 Interview SQL Question with Detailed Explanation | Practice SQL
17:11
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
LeetCode 197: Rising Temperature [SQL]
8:20
Frederik Müller
Рет қаралды 20 М.
LeetCode 626: Exchange Seats [SQL]
7:58
Frederik Müller
Рет қаралды 9 М.
LeetCode 1454: Active Users [SQL]
14:01
Frederik Müller
Рет қаралды 6 М.
LeetCode 550: Game Play Analysis IV [SQL]
8:31
Frederik Müller
Рет қаралды 9 М.
LeetCode 182: Duplicate Emails [3 Solutions]
11:49
Frederik Müller
Рет қаралды 10 М.
LeetCode 181: Employees Earning More Than Their Managers [SQL]
8:28
Frederik Müller
Рет қаралды 14 М.
LeetCode 1270: All People Report to the Given Manager [SQL]
10:09
Frederik Müller
Рет қаралды 4,6 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН