Skip to content

Commit 65b7839

Browse files
add solution for leetcode 176 181 595
1 parent 402f1a8 commit 65b7839

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
|628|[Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers/) | |Easy|
7373
|627|[Swap Salary](https://leetcode.com/problems/swap-salary/) | [Mysql](./algorithm/swapSalary/Solution.java) | |Easy|
7474
|623|[Add One Row to Tree](https://leetcode.com/problems/add-one-row-to-tree/) | |Medium|
75+
|595|[Big Countries](https://leetcode.com/problems/big-countries/)| [Mysql](./algorithms/bigCountries/Solution.sql) |Easy|
7576
|581|[Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray/) | |Easy|
7677
|572|[Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/) | |Easy|
7778
|563|[Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt/) | [java](./algorithms/binaryTreeTilt/Solution.java) |Easy|
@@ -240,7 +241,9 @@
240241
|186|[Reverse Words in a String II](https://leetcode.com/problems/reverse-words-in-a-string-ii/) ♥ | |Medium|
241242
|183|[Customers Who Never Order](https://leetcode.com/problems/customers-who-never-order/)| [Mysql](./algorithms/customersWhoNeverOrder/Solution.sql) |Easy|
242243
|182|[Duplicate Email](https://leetcode.com/problems/duplicate-emails/)| [Mysql](./algorithms/duplicateEmails/Solution.sql) |Easy|
244+
|181|[Employees Earning More Than Their Managers](https://leetcode.com/problems/employees-earning-more-than-their-managers/)| [Mysql](./algorithms/employeesEarningMoreThanTheirManagers/Solution.sql) |Easy|
243245
|179|[Largest Number](https://leetcode.com/problems/largest-number/) | |Medium|
246+
|176|[Second Highest Salary](https://leetcode.com/problems/second-highest-salary/)| [Mysql](./algorithms/secondHightestSalary/Solution.sql) |Easy|
244247
|175|[Combine Two Tables](https://leetcode.com/problems/combine-two-tables/)| [Mysql](./algorithms/combineTwoTable/Solution.sql) |Easy|
245248
|174|[Dungeon Game](https://leetcode.com/problems/dungeon-game/) | |Hard|
246249
|173|[Binary Search Tree Iterator](https://leetcode.com/problems/binary-search-tree-iterator/) | |Medium|

algorithms/bigCountries/Solution.sql

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- UNION 连接自查询 或者 使用 Where Or
2+
-- 因为 where or 比较熟悉 采用 UNION 进行题解
3+
4+
SELECT
5+
name, population, area
6+
FROM
7+
world
8+
WHERE
9+
area > 3000000
10+
11+
UNION
12+
13+
SELECT
14+
name, population, area
15+
FROM
16+
world
17+
WHERE
18+
population > 25000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- 第一种连接两个表的方式
2+
SELECT
3+
a.Name AS 'Employee'
4+
FROM
5+
Employee AS a,
6+
Employee AS b
7+
WHERE
8+
a.ManagerId = b.Id
9+
AND a.Salary > b.Salary
10+
;
11+
12+
-- 使用 JOIN 单独进行两张表连接
13+
SELECT
14+
a.Name AS 'Employee'
15+
FROM
16+
Employee AS a,
17+
Employee AS b
18+
WHERE
19+
a.ManagerId = b.Id
20+
AND a.Salary > b.Salary
21+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- 使用 DISTINCT 进行去重
2+
SELECT
3+
(SELECT DISTINCT
4+
Salary
5+
FROM
6+
Employee
7+
ORDER BY Salary DESC
8+
LIMIT 1 OFFSET 1) AS SecondHighestSalary

0 commit comments

Comments
 (0)