8000 add : 620 · h-j-13/LeetCode-Database@82dd2cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 82dd2cd

Browse files
committed
add : 620
1 parent e43348e commit 82dd2cd

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
# LeetCode 620. Not Boring Movies
3+
## 题目
4+
X city opened a new ```cinema```, many people would like to go to this cinema. The cinema also gives out a poster indicating the movies’ ratings and descriptions.
5+
6+
Please write a SQL query to output movies with an odd numbered ID and a description that is not 'boring'. Order the result by rating.
7+
8+
For example, table cinema:
9+
```
10+
+---------+-----------+--------------+-----------+
11+
| id | movie | description | rating |
12+
+---------+-----------+--------------+-----------+
13+
| 1 | War | great 3D | 8.9 |
14+
| 2 | Science | fiction | 8.5 |
15+
| 3 | irish | boring | 6.2 |
16+
| 4 | Ice song | Fantacy | 8.6 |
17+
| 5 | House card| Interesting| 9.1 |
18+
+---------+-----------+--------------+-----------+
19+
```
20+
For the example above, the output should be:
21+
```
22+
+---------+-----------+--------------+-----------+
23+
| id | movie | description | rating |
24+
+---------+-----------+--------------+-----------+
25+
| 5 | House card| Interesting| 9.1 |
26+
| 1 | War | great 3D | 8.9 |
27+
+---------+-----------+--------------+-----------+
28+
```
29+
题目大意:请输入一个SQL查询来输出带有奇数编号的ID和不是“无聊”的描述。按等级排序结果。
30+
31+
## 解题思路
32+
直接写SQL 就好了
33+
奇数用对2取余为1来表示即可
34+
35+
```SQL
36+
SELECT * FROM cinema WHERE id % 2 = 1 AND description != 'boring' ORDER BY rating DESC
37+
```
38+
39+
发现也可以这样表示取余
40+
```sql
41+
select * from cinema where mod(id, 2) = 1 and description != 'boring' order by rating DESC
42+
```
43+
44+
45+

0 commit comments

Comments
 (0)
0