Skip to content

Commit 1d7aa62

Browse files
author
Danieldu
committed
add 181-185 sql
1 parent df3f04e commit 1d7aa62

5 files changed

+104
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--
2+
-- @lc app=leetcode id=181 lang=mysql
3+
--
4+
-- [181] Employees Earning More Than Their Managers
5+
--
6+
7+
-- @lc code=start
8+
# Write your MySQL query statement below
9+
10+
SELECT
11+
e.name AS Employee
12+
FROM
13+
Employee e
14+
WHERE
15+
e.managerId IS NOT NULL
16+
AND e.salary > (
17+
SELECT m.salary
18+
FROM Employee m
19+
WHERE m.id = e.managerId
20+
);
21+
-- @lc code=end
22+

SQL/182.duplicate-emails.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--
2+
-- @lc app=leetcode id=182 lang=mysql
3+
--
4+
-- [182] Duplicate Emails
5+
--
6+
7+
-- @lc code=start
8+
# Write your MySQL query statement below
9+
SELECT
10+
email AS Email
11+
FROM
12+
Person
13+
GROUP BY
14+
email
15+
HAVING
16+
COUNT(*) > 1;
17+
-- @lc code=end
18+

SQL/183.customers-who-never-order.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
-- @lc code=start
88
# Write your MySQL query statement below
9-
select name as Customers from Customers where Customers.id not in (select customerId from Orders)
9+
SELECT
10+
name AS Customers
11+
FROM
12+
Customers
13+
WHERE
14+
Customers.id NOT IN (
15+
SELECT customerId FROM Orders
16+
)
1017
-- @lc code=end
1118

SQL/184.department-highest-salary.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--
2+
-- @lc app=leetcode id=184 lang=mysql
3+
--
4+
-- [184] Department Highest Salary
5+
--
6+
7+
-- @lc code=start
8+
# Write your MySQL query statement below
9+
SELECT
10+
d.name AS Department,
11+
e.name AS Employee,
12+
e.salary AS Salary
13+
FROM
14+
Employee e
15+
JOIN Department d
16+
ON e.departmentId = d.id
17+
WHERE
18+
e.salary = (
19+
SELECT MAX(salary)
20+
FROM Employee
21+
WHERE departmentId = e.departmentId
22+
)
23+
ORDER BY
24+
d.name,
25+
e.name;
26+
-- @lc code=end
27+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--
2+
-- @lc app=leetcode id=185 lang=mysql
3+
--
4+
-- [185] Department Top Three Salaries
5+
--
6+
7+
-- @lc code=start
8+
# Write your MySQL query statement below
9+
SELECT
10+
d.name AS Department,
11+
e.name AS Employee,
12+
e.salary AS Salary
13+
FROM
14+
Employee e
15+
JOIN Department d
16+
ON e.departmentId = d.id
17+
WHERE
18+
(
19+
SELECT COUNT(DISTINCT salary)
20+
FROM Employee x
21+
WHERE
22+
x.departmentId = e.departmentId
23+
AND x.salary > e.salary
24+
) < 3
25+
ORDER BY
26+
Department ASC,
27+
Salary DESC;
28+
-- @lc code=end
29+

0 commit comments

Comments
 (0)