LeetCode 626: Exchange Seats [SQL]

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

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 10 ай бұрын
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 10 ай бұрын
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!!!
@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
@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;
@HenggaoCai
@HenggaoCai 4 жыл бұрын
You explain very well. Your explanations are clear.
@jackyychn7053
@jackyychn7053 Жыл бұрын
Smart move, as I was struggling with exchanging names.
@kaushikpasikanti9025
@kaushikpasikanti9025 3 жыл бұрын
Clear, simple explanation!
@dantenekomew
@dantenekomew 9 ай бұрын
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 8 ай бұрын
what is the use of id%1=0
@danielsaavedra9238
@danielsaavedra9238 2 ай бұрын
this approach makes more sense. TY
@navneetberi910
@navneetberi910 3 жыл бұрын
you explained it so well.
@the_fat_journal
@the_fat_journal 4 жыл бұрын
Smart, thank you.
@yourbestie4138
@yourbestie4138 2 жыл бұрын
good one
@zhihaoxu8119
@zhihaoxu8119 3 жыл бұрын
Lengendary
LeetCode 1341: Movie Rating [SQL]
18:35
Frederik Müller
Рет қаралды 258
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
LeetCode Medium 626 Amazon Interview SQL Question with Detailed Explanation
8:38
LeetCode 1454: Active Users [SQL]
14:01
Frederik Müller
Рет қаралды 6 М.
LeetCode 181: Employees Earning More Than Their Managers [SQL]
8:28
Frederik Müller
Рет қаралды 15 М.
LeetCode 262: Trips and Users [SQL]
9:28
Frederik Müller
Рет қаралды 10 М.
Solving one of PostgreSQL's biggest weaknesses.
17:12
Dreams of Code
Рет қаралды 227 М.
40. Restaurant Growth | SQL Interview Questions and Answers
13:12
Start Practicing
Рет қаралды 2,4 М.
Database Indexing for Dumb Developers
15:59
Laith Academy
Рет қаралды 88 М.
LeetCode Medium 1341 "Movie Rating" SAP Interview SQL Question with Explanation
12:04