Skip to content

Commit b325f59

Browse files
add sql solution for leetcode 1179 620 178
1 parent 5e93250 commit b325f59

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
| # | Title | Solution | Difficulty |
66
|---| ----- | -------- | ---------- |
77
|1207|[Unique Number of Occurrences](https://leetcode.com/problems/unique-number-of-occurrences/) | |Easy|
8+
|1179|[Reformat Department Table](https://leetcode.com/problems/reformat-department-table/)| [Mysql](./algorithms/reformatDepartmentTable/Solution.sql) |Easy|
89
|1170|[Compare Strings by Frequency of the Smallest Character](https://leetcode.com/problems/compare-strings-by-frequency-of-the-smallest-character/) | |Easy|
910
|1137|[N-th Tribonacci Number](https://leetcode.com/problems/n-th-tribonacci-number/) | [js](./algorithms/nThTribonacciNumber/nThTribonacciNumber.js) |Easy|
1011
|1071|[Greatest Common Divisor of Strings](https://leetcode.com/problems/greatest-common-divisor-of-strings/) | |Easy|
@@ -73,6 +74,7 @@
7374
|628|[Maximum Product of Three Numbers](https://leetcode.com/problems/maximum-product-of-three-numbers/) | |Easy|
7475
|627|[Swap Salary](https://leetcode.com/problems/swap-salary/) | [Mysql](./algorithm/swapSalary/Solution.java) | |Easy|
7576
|623|[Add One Row to Tree](https://leetcode.com/problems/add-one-row-to-tree/) | |Medium|
77+
|620|[Not Boring Movies](https://leetcode.com/problems/not-boring-movies/)| [Mysql](./algorithms/notBoringMovies/Solution.sql) |Easy|
7678
|595|[Big Countries](https://leetcode.com/problems/big-countries/)| [Mysql](./algorithms/bigCountries/Solution.sql) |Easy|
7779
|581|[Shortest Unsorted Continuous Subarray](https://leetcode.com/problems/shortest-unsorted-continuous-subarray/) | |Easy|
7880
|572|[Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/) | |Easy|
@@ -246,6 +248,7 @@
246248
|182|[Duplicate Email](https://leetcode.com/problems/duplicate-emails/)| [Mysql](./algorithms/duplicateEmails/Solution.sql) |Easy|
247249
|181|[Employees Earning More Than Their Managers](https://leetcode.com/problems/employees-earning-more-than-their-managers/)| [Mysql](./algorithms/employeesEarningMoreThanTheirManagers/Solution.sql) |Easy|
248250
|179|[Largest Number](https://leetcode.com/problems/largest-number/) | |Medium|
251+
|178|[Ranking Scores](https://leetcode.com/problems/rank-scores/)| [Mysql](./algorithms/rankScores/Solution.sql) |Easy|
249252
|177|[Nth Highest Salary](https://leetcode.com/problems/nth-highest-salary/)| [Mysql](./algorithms/nthHightestSalary/Solution.sql) |Easy|
250253
|176|[Second Highest Salary](https://leetcode.com/problems/second-highest-salary/)| [Mysql](./algorithms/secondHightestSalary/Solution.sql) |Easy|
251254
|175|[Combine Two Tables](https://leetcode.com/problems/combine-two-tables/)| [Mysql](./algorithms/combineTwoTable/Solution.sql) |Easy|
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-- Write your MySQL query statement below
2+
-- 利用 mod 函数判断 奇偶
3+
select *
4+
from cinema
5+
where mod(id, 2) = 1 and description != 'boring'
6+
order by rating DESC
7+
;

algorithms/rankScores/Solution.sql

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Write your MySQL query statement below
2+
-- 使用 DENSE_RANK() 函数 进行 排序
3+
select score, DENSE_RANK() OVER (ORDER BY Score DESC) as 'Rank'
4+
from Scores;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- # Write your MySQL query statement below
2+
-- 利用 group by 进行行转列
3+
SELECT id,
4+
SUM(CASE WHEN month='Jan' THEN revenue END) AS Jan_Revenue,
5+
SUM(CASE WHEN month='Feb' THEN revenue END) AS Feb_Revenue,
6+
SUM(CASE WHEN month='Mar' THEN revenue END) AS Mar_Revenue,
7+
SUM(CASE WHEN month='Apr' THEN revenue END) AS Apr_Revenue,
8+
SUM(CASE WHEN month='May' THEN revenue END) AS May_Revenue,
9+
SUM(CASE WHEN month='Jun' THEN revenue END) AS Jun_Revenue,
10+
SUM(CASE WHEN month='Jul' THEN revenue END) AS Jul_Revenue,
11+
SUM(CASE WHEN month='Aug' THEN revenue END) AS Aug_Revenue,
12+
SUM(CASE WHEN month='Sep' THEN revenue END) AS Sep_Revenue,
13+
SUM(CASE WHEN month='Oct' THEN revenue END) AS Oct_Revenue,
14+
SUM(CASE WHEN month='Nov' THEN revenue END) AS Nov_Revenue,
15+
SUM(CASE WHEN month='Dec' THEN revenue END) AS Dec_Revenue
16+
FROM department
17+
GROUP BY id
18+
ORDER BY id;

0 commit comments

Comments
 (0)