620. Not Boring Movies

题目描述和难度

  • 题目描述:

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

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

 

例如,下表 cinema:

+---------+-----------+--------------+-----------+
|   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     |
+---------+-----------+--------------+-----------+

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

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

 

思路分析

求解关键:

drop table if exists cinema;
create table cinema(
  id int primary key auto_increment,
  movie varchar(100),
  description varchar(100),
  rating double
);

insert into cinema(movie,description,rating) values('War','great 3D',8.9);
insert into cinema(movie,description,rating) values('Science','fiction',8.5);
insert into cinema(movie,description,rating) values('irish','boring',6.2);
insert into cinema(movie,description,rating) values('Ice song','Fantacy',8.6);
insert into cinema(movie,description,rating) values('House card','Interesting',9.1);

参考解答

参考解答1

select id, movie, description, rating 
from cinema 
where description != 'boring' and id % 2 = 1
order by rating desc;

本篇文章的地址为 https://liweiwei1419.github.io/leetcode-solution/leetcode-0620-not-boring-movies ,如果我的题解有错误,或者您有更好的解法,欢迎您告诉我 liweiwei1419@gmail.com