Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit580bfb2

Browse files
committed
update: 7 solutions
1 parent0e9c1a9 commit580bfb2

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

‎README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
This is the solution collection of my LeetCode problems, most of them are programmed in JavaScript.
44

5-
Progress:4/
5+
Progress:7/
66

77
| ID| Title| Solution| Difficulty|
88
|---| -----| --------| ----------|
99
|1|[Two Sum](https://leetcode.com/problems/two-sum/)|[JavaScript](./src/two-sum/res.js)|Easy|
1010
|2|[Add Two Numbers](https://leetcode.com/problems/add-two-numbers/)|[JavaScript](./src/add-two-numbers/res.js)|Medium|
1111
|175|[Combine Two Tables](https://leetcode.com/problems/combine-two-tables/)|[SQL](./src/combine-two-tables/res.txt)|Easy|
12+
|176|[Second Highest Salary](https://leetcode.com/problems/second-highest-salary/)|[SQL](./src/second-highest-salary/res.txt)|Easy|
1213
|181|[Employees Earning More Than Their Managers](https://leetcode.com/problems/employees-earning-more-than-their-managers/)|[SQL](./src/employees-earning-more-than-their-managers/res.txt)|Easy|
14+
|182|[Duplicate Emails](https://leetcode.com/problems/duplicate-emails/)|[SQL](./src/duplicate-emails/res.txt)|Easy|
1315
|434|[Number of Segments in a String](https://leetcode.com/problems/number-of-segments-in-a-string/)|[JavaScript](./src/number-of-segments-in-a-string/res.js)|Easy|

‎src/duplicate-emails/res.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- Write a SQL query to find all duplicate emails in a table named Person.
2+
3+
-- +----+---------+
4+
-- | Id | Email |
5+
-- +----+---------+
6+
-- | 1 | a@b.com |
7+
-- | 2 | c@d.com |
8+
-- | 3 | a@b.com |
9+
-- +----+---------+
10+
-- For example, your query should return the following for the above table:
11+
12+
-- +---------+
13+
-- | Email |
14+
-- +---------+
15+
-- | a@b.com |
16+
-- +---------+
17+
-- Note: All emails are in lowercase.
18+
19+
# Write your MySQL query statement below
20+
SELECT t.eml AS 'Email' FROM
21+
(SELECT count(Email) AS 'cnt', Email AS 'eml' FROM Person GROUP BY Email) as t
22+
WHERE t.cnt>1;

‎src/second-highest-salary/res.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- Write a SQL query to get the second highest salary from the Employee table.
2+
3+
-- +----+--------+
4+
-- | Id | Salary |
5+
-- +----+--------+
6+
-- | 1 | 100 |
7+
-- | 2 | 200 |
8+
-- | 3 | 300 |
9+
-- +----+--------+
10+
-- For example, given the above Employee table, the second highest salary is 200. If there is no second highest salary, then the query should return null.
11+
12+
# Note @hijiangtao
13+
# You should rename the result header as SecondHighestSalary.
14+
# NOT IN condition will consume much more time than < condition
15+
# Note @hijiangtao
16+
17+
# Write your MySQL query statement below
18+
SELECT MAX(Salary) AS "SecondHighestSalary" FROM Employee
19+
WHERE Salary < (SELECT MAX(Salary) FROM Employee )
20+
21+
# Another solution
22+
SELECT MAX(Salary) AS "SecondHighestSalary" FROM Employee
23+
WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee )

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp