LeetCode 626: Exchange Seats [SQL]

  Рет қаралды 9,468

Frederik Müller

Frederik Müller

Күн бұрын

Пікірлер: 20
@amrqura
@amrqura 3 жыл бұрын
Thanks alot for your explanation. I would say using window function can be more efficient here, here is an example: select id, case when id%2=1 then lead(student,1,student) over (order by id) else lag(student) over(order by id) End as student from Seat
@mritunzaysingh8978
@mritunzaysingh8978 2 жыл бұрын
thank you sir .. for your answer it really meaningful and understandable
@yeah6732
@yeah6732 2 жыл бұрын
Very good solution, thank you!!
@minimumeffort1997
@minimumeffort1997 9 ай бұрын
I like how you solve all the problems with basic logic instead of using fancy terminologies. As programmers , we should stick to logic instead of using fancy built in functions.
@frederikmuller
@frederikmuller 9 ай бұрын
yes, the goal is to make everyone understand and not use fancy terminology and functions just for the sake of using them.
@anboyao6125
@anboyao6125 3 жыл бұрын
You explained so well bro. A lot of questions I was so confused looking at the answer. You are so good!!!
@HenggaoCai
@HenggaoCai 3 жыл бұрын
You explain very well. Your explanations are clear.
@ahmadmohamadi
@ahmadmohamadi 4 жыл бұрын
MS SQL: select id, case when mod(id,2)=0 then lag(student) over (order by id) when lead(student) over (order by id) IS NULL then student else lead(student) over (order by id) end as student from seat order by id
@kaushikpasikanti9025
@kaushikpasikanti9025 3 жыл бұрын
Clear, simple explanation!
@mritunzaysingh8978
@mritunzaysingh8978 2 жыл бұрын
I solved this query by using windows function create TABLE seat ( id int not null primary key, name VARCHAR(20) ); insert into seat VALUES(1,'Raman'),(2,'Sanjiv'),(3,'Saloni'),(4,'Shweta'),(5,'Mohit'); select * from seat; select *, case when id%2 != 0 then lead(name,1,name) over(ORDER by id) when id%2 = 0 then lag(name) over(ORDER by id) else name END as exchange_seat_student_name from seat;
@jackyychn7053
@jackyychn7053 Жыл бұрын
Smart move, as I was struggling with exchanging names.
@navneetberi910
@navneetberi910 3 жыл бұрын
you explained it so well.
@dantenekomew
@dantenekomew 8 ай бұрын
Another logic approach is to get the previous and next student name and decide which to display, it is much cleaner and easier to understand solution:: SELECT id, CASE WHEN id % 2 = 0 THEN LAG(student, 1) OVER() #even show previous WHEN id % 1 = 0 AND LEAD(student, 1) OVER() IS NOT NULL THEN LEAD(student, 1) OVER() #odd show next ELSE student #last record/row END as student FROM Seat
@vichitravirdwivedi
@vichitravirdwivedi 7 ай бұрын
what is the use of id%1=0
@danielsaavedra9238
@danielsaavedra9238 Ай бұрын
this approach makes more sense. TY
@the_fat_journal
@the_fat_journal 4 жыл бұрын
Smart, thank you.
@yourbestie4138
@yourbestie4138 2 жыл бұрын
good one
@zhihaoxu8119
@zhihaoxu8119 3 жыл бұрын
Lengendary
LeetCode 185: Department Top Three Salaries [SQL]
9:33
Frederik Müller
Рет қаралды 15 М.
LeetCode 1204: Last Person to Fit in the Elevator/Bus [SQL]
10:26
Frederik Müller
Рет қаралды 5 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Гениальное изобретение из обычного стаканчика!
00:31
Лютая физика | Олимпиадная физика
Рет қаралды 4,8 МЛН
LeetCode 1270: All People Report to the Given Manager [SQL]
10:09
Frederik Müller
Рет қаралды 4,6 М.
1341. Movie Rating - LeetCode SQL Solution
8:24
Code with Carter
Рет қаралды 1,2 М.
LeetCode 1280: Students and Examinations - Interview Prep Ep 23
12:36
I tried 8 different Postgres ORMs
9:46
Beyond Fireship
Рет қаралды 441 М.
Systems Design in an Hour
1:11:00
Jordan has no life
Рет қаралды 34 М.
LeetCode Medium 1341 "Movie Rating" SAP Interview SQL Question with Explanation
12:04
LeetCode 1251 Interview SQL Question with Detailed Explanation | Practice SQL
17:11
SQL Window Functions in 10 Minutes
10:13
Colt Steele
Рет қаралды 92 М.