[LeetCode] 181.Employees Earning More Than Their ManagersThe Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.
Given the Employee table, write a SQL query that finds out employees who earn more than their managers. For the above table, Joe is the only employee who earns more than his manager.
This question gives us an Employee table, which contains the salary information of employees and their managers. Managers are also employees, and their manager ID is empty. Let's find out the employees whose salary is higher than their managers. Then it is a very simple comparison problem. We can generate two instance objects to interpolate through ManagerId and Id, and then restrict the condition that one Salary is greater than the other: Solution 1: SELECT e1.Name FROM Employee e1 JOIN Employee e2 ON e1.ManagerId = e2.Id WHERE e1.Salary > e2.Salary; We can also skip Join and directly write all the conditions into where: Solution 2: SELECT e1.Name FROM Employee e1, Employee e2 WHERE e1.ManagerId = e2.Id AND e1.Salary > e2.Salary; References: https://leetcode.com/discuss/88189/two-straightforward-way-using-where-and-join This is the end of this article about SQL implementation of LeetCode (181. Employees earn more than managers). For more relevant SQL implementation of employees earning more than managers, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to use CSS to fill the parent container div with img images and adjust the container size
>>: How to make an input text box change length according to its content
Table of contents 1. Install the proxy module 2. ...
Table of contents Background Configuring DHCP Edi...
MyISAM storage engine MyISAM is based on the ISAM...
A transaction is a logical group of operations. E...
Table of contents 1. Scene introduction 2 Code Op...
1. Download docker online yum install -y epel-rel...
This article example shares the specific code of ...
Often, after a web design is completed, the desig...
Table of contents 1. Two-way binding 2. Will the ...
Does performance really matter? Performance is im...
Preface Tomcat is a widely used Java web containe...
First, download the installation package from the...
After studying React for a while, I want to put i...
nginx server nginx is an excellent web server tha...
1. CSS element hiding <br />In CSS, there ar...