LeetCode每天一题

620. 有趣的电影

620. 有趣的电影

难度简单86

SQL架构

某城市开了一家新的电影院,吸引了很多人过来看电影。该电影院特别注意用户体验,专门有个 LED显示板做电影推荐,上面公布着影评和相关电影描述。

作为该电影院的信息部主管,您需要编写一个 SQL查询,找出所有影片描述为 boring (不无聊) 的并且 id 为奇数 的影片,结果请按等级 rating 排列。

例如,下表 cinema:

1
2
3
4
5
6
7
8
9
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 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 |
+---------+-----------+--------------+-----------+

对于上面的例子,则正确的输出是为:

1
2
3
4
5
6
+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 5 | House card| Interesting| 9.1 |
| 1 | War | great 3D | 8.9 |
+---------+-----------+--------------+-----------+

通过次数49,161

提交次数64,602

解题思路

这个查询很简单,只需要写两个条件,并进行排序即可

两个条件:影片描述为 boring (不无聊) 的并且 id 为奇数

排序规则:按等级 rating 排列,倒序排列

1
2
where id%2=1 and description!="boring"
group by rating desc;

答案解析

1
2
3
4
5
# Write your MySQL query statement below
select id,movie,description,rating
from cinema
where id%2=1 and description!="boring"
order by rating desc;

image-20200725094957908

点击查看
-------------------本文结束 感谢您的阅读-------------------