Skip to content

Commit 6da1e8f

Browse files
committed
Add solution 620 [sql]
mod order by
1 parent 68fd3ed commit 6da1e8f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Complete [solutions](https://github.com/doocs/leetcode/tree/master/solution) to
5252
| 595 | [Big Countries](https://github.com/doocs/leetcode/tree/master/solution/595.Big%20Countries) | `SQL` |
5353
| 596 | [Classes More Than 5 Students](https://github.com/doocs/leetcode/tree/master/solution/596.Classes%20More%20Than%205%20Students) | `SQL` |
5454
| 605 | [Can Place Flowers](https://github.com/doocs/leetcode/tree/master/solution/605.Can%20Place%20Flowers) | `Array` |
55+
| 620 | [Not Boring Movies](https://github.com/doocs/leetcode/tree/master/solution/620.Not%20Boring%20Movies) | `SQL` |
5556
| 627 | [Swap Salary](https://github.com/doocs/leetcode/tree/master/solution/627.Swap%20Salary) | `SQL` |
5657
| 695 | [Max Area of Island](https://github.com/doocs/leetcode/tree/master/solution/695.Max%20Area%20of%20Island) | `Array`, `Depth-first Search` |
5758
| 703 | [Kth Largest Element in a Stream](https://github.com/doocs/leetcode/tree/master/solution/703.Kth%20Largest%20Element%20in%20a%20Stream) | `Heap` |
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## 有趣的电影
2+
### 题目描述
3+
4+
5+
某城市开了一家新的电影院,吸引了很多人过来看电影。该电影院特别注意用户体验,专门有个 LED显示板做电影推荐,上面公布着影评和相关电影描述。
6+
7+
作为该电影院的信息部主管,您需要编写一个 SQL查询,找出所有影片描述为**** `boring` (不无聊) 的并且 **id 为奇数** 的影片,结果请按等级 `rating` 排列。
8+
9+
10+
11+
例如,下表 `cinema`:
12+
```
13+
+---------+-----------+--------------+-----------+
14+
| id | movie | description | rating |
15+
+---------+-----------+--------------+-----------+
16+
| 1 | War | great 3D | 8.9 |
17+
| 2 | Science | fiction | 8.5 |
18+
| 3 | irish | boring | 6.2 |
19+
| 4 | Ice song | Fantacy | 8.6 |
20+
| 5 | House card| Interesting| 9.1 |
21+
+---------+-----------+--------------+-----------+
22+
```
23+
24+
对于上面的例子,则正确的输出是为:
25+
```
26+
+---------+-----------+--------------+-----------+
27+
| id | movie | description | rating |
28+
+---------+-----------+--------------+-----------+
29+
| 5 | House card| Interesting| 9.1 |
30+
| 1 | War | great 3D | 8.9 |
31+
+---------+-----------+--------------+-----------+
32+
```
33+
34+
### 解法
35+
简单查询即可。
36+
37+
```sql
38+
# Write your MySQL query statement below
39+
40+
select id, movie, description, rating
41+
from cinema
42+
where description != 'boring' and mod(id, 2) = 1
43+
order by rating desc;
44+
45+
```
46+
47+
#### Input
48+
```json
49+
{"headers":{"cinema":["id", "movie", "description", "rating"]},"rows":{"cinema":[[1, "War", "great 3D", 8.9], [2, "Science", "fiction", 8.5], [3, "irish", "boring", 6.2], [4, "Ice song", "Fantacy", 8.6], [5, "House card", "Interesting", 9.1]]}}
50+
```
51+
52+
#### Output
53+
```json
54+
{"headers":["id","movie","description","rating"],"values":[[5,"House card","Interesting",9.1],[1,"War","great 3D",8.9]]}
55+
```

0 commit comments

Comments
 (0)