Skip to content

Commit 5987598

Browse files
committed
update: 1 solution
1 parent 580bfb2 commit 5987598

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

README.md

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

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

5-
Progress: 7/
5+
Progress: 9/
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|
1212
|176|[Second Highest Salary](https://leetcode.com/problems/second-highest-salary/)| [SQL](./src/second-highest-salary/res.txt)|Easy|
13+
|177|[Nth Highest Salary](https://leetcode.com/problems/nth-highest-salary/)| [SQL](./src/nth-highest-salary/res.txt)|Medium|
1314
|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|
1415
|182|[Duplicate Emails](https://leetcode.com/problems/duplicate-emails/) | [SQL](./src/duplicate-emails/res.txt)|Easy|
16+
|197|[Rising Temperature](https://leetcode.com/problems/rising-temperature/) | [SQL](./src/rising-temperature/res.txt)|Easy|
1517
|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/nth-highest-salary/res.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Write a SQL query to get the nth 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 nth highest salary where n = 2 is 200. If there is no nth highest salary, then the query should return null.
11+
12+
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
13+
BEGIN
14+
DECLARE M INT;
15+
SET M=N-1;
16+
RETURN (
17+
# Write your MySQL query statement below.
18+
SELECT DISTINCT Salary FROM Employee ORDER BY Salary DESC LIMIT M,1
19+
);
20+
END

src/rising-temperature/res.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates.
2+
3+
-- +---------+------------+------------------+
4+
-- | Id(INT) | Date(DATE) | Temperature(INT) |
5+
-- +---------+------------+------------------+
6+
-- | 1 | 2015-01-01 | 10 |
7+
-- | 2 | 2015-01-02 | 25 |
8+
-- | 3 | 2015-01-03 | 20 |
9+
-- | 4 | 2015-01-04 | 30 |
10+
-- +---------+------------+------------------+
11+
-- For example, return the following Ids for the above Weather table:
12+
-- +----+
13+
-- | Id |
14+
-- +----+
15+
-- | 2 |
16+
-- | 4 |
17+
-- +----+
18+
19+
# Write your MySQL query statement below
20+
SELECT a.Id AS 'Id' FROM Weather a INNER JOIN Weather b ON a.Temperature > b.Temperature AND DATEDIFF(a.Date, b.Date)=1

0 commit comments

Comments
 (0)