No video

LeetCode 181: Employees Earning More Than Their Managers [SQL]

  Рет қаралды 14,477

Frederik Müller

Frederik Müller

3 жыл бұрын

Solution and walkthrough of leetcode database problem 181: Employees Earning More Than Their Managers. I'm using MySQL but this solution should work in any SQL dialect such as PostgreSQL SQL Server, etc.
Link to the problem: leetcode.com/p...

Пікірлер: 22
@abinayen
@abinayen 2 жыл бұрын
really helping me study, thank you for all the clear explanations!
@shivambaghel9668
@shivambaghel9668 2 жыл бұрын
you deserves more likes and subscribes
@rudrapriyan5162
@rudrapriyan5162 4 ай бұрын
Do you think if we EXISTS it would reduce the time complexity or the number of tuples it has to olerate on ?
@VedPrakashLearnToGrow
@VedPrakashLearnToGrow 3 жыл бұрын
Awesome Explanation, Thank you
@vgaurav3011
@vgaurav3011 3 жыл бұрын
Nice explanation, loved it!
@angelalu3855
@angelalu3855 2 жыл бұрын
very useful! thanks a lot!
@zeeshanali271
@zeeshanali271 2 жыл бұрын
I still don't understand the ON clause position statement
@rachcastellino
@rachcastellino 3 жыл бұрын
when you are matching on managerID and ID, why does it pair together ID's that aren't the same value? is this supposed to create all combinations of employees?
@frederikmuller
@frederikmuller 3 жыл бұрын
the join takes the ManagerId of a row and looks for a matching (regular) Id. it seems like you mixed up ManagerId and Id. take a look at the output at 4:21 to see how the 4th and 5th column always match. managers also have a regular Id which can't match the regular Id of another employee since these Ids are unique. hope this helps :)
@TheProximator
@TheProximator 3 жыл бұрын
Nice, thanks a lot :)
@frederikmuller
@frederikmuller 3 жыл бұрын
You're welcome!
@yueleji8892
@yueleji8892 3 жыл бұрын
could you explain the difference between using ' on and' and 'where' in left join? for example leetcode 577? Thank you!
@frederikmuller
@frederikmuller 3 жыл бұрын
good idea for an upcoming video!
@semantosaini9600
@semantosaini9600 3 жыл бұрын
why in the on clause it is e1.managerid=e2.id and not e1.id=e2.managerid?
@vinoddiwan5792
@vinoddiwan5792 2 жыл бұрын
because from e1 table first we need to find if its manager exists or not . If exists then match from main table e.i id . So, e1.manager id id the foreign key because we need to first find if it exists in other table or not.
@mritunzaysingh8978
@mritunzaysingh8978 Жыл бұрын
create table employee (id int not null PRIMARY key, name varchar(20), salary int, managerid int ); insert into employee VALUES(1,'JOE',7000,3),(2,'MARRY',8000,4),(3,'SAM',6000,NULL),(4,'MAX',9000,NULL); select * from employee; select E.name,E.salary as emp_salary,M.salary as manager_salary from employee as E join employee as M on E.managerid = M.id where E.salary > M.salary; select E.name as emp_name from employee as E join employee as M on E.managerid = M.id where E.salary > M.salary;
@avahome5285
@avahome5285 2 жыл бұрын
self join to get the employee's salary and the manager's salary in a row.
@JesusReigns7
@JesusReigns7 Жыл бұрын
Is this still in SQL?
@alibhaiacademy2981
@alibhaiacademy2981 3 жыл бұрын
Thanks, my solution SELECT name AS "Employee" FROM employee e WHERE managerid IN ( SELECT id FROM employee m WHERE e.salary > m.salary
@mickyman753
@mickyman753 2 жыл бұрын
I wrote it like this , don't know why that join doesn't click when I'm doing problems , although I'm doing the same thing select e1.name as Employee from Employee e1 where e1.salary>(select e2.salary from Employee e2 where e2.id=e1.ManagerId);
@arnabpersonal6729
@arnabpersonal6729 3 жыл бұрын
I see u like white a lot
@frederikmuller
@frederikmuller 3 жыл бұрын
yeah
LeetCode 182: Duplicate Emails [3 Solutions]
11:49
Frederik Müller
Рет қаралды 10 М.
LeetCode 262: Trips and Users [SQL]
9:28
Frederik Müller
Рет қаралды 9 М.
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 36 МЛН
OMG what happened??😳 filaretiki family✨ #social
01:00
Filaretiki
Рет қаралды 11 МЛН
LeetCode 176: Second Highest Salary [SQL]
7:19
Frederik Müller
Рет қаралды 19 М.
LeetCode 626: Exchange Seats [SQL]
7:58
Frederik Müller
Рет қаралды 9 М.
LeetCode 177: Nth Highest Salary [SQL]
6:40
Frederik Müller
Рет қаралды 23 М.
LeetCode 197: Rising Temperature [SQL]
8:20
Frederik Müller
Рет қаралды 17 М.
Clustered vs. Nonclustered Index Structures in SQL Server
8:04
Voluntary DBA
Рет қаралды 650 М.
LeetCode 183: Customers Who Never Order [SQL]
6:08
Frederik Müller
Рет қаралды 12 М.