620.编写解决方案,找出所有影片描述为 非 boring (不无聊) 的并且 id 为奇数 的影片,返回结果按 rating 降序排列
题目链接:
https://leetcode.cn/problems/not-boring-movies/
建表插入数据:
Create table If Not Exists cinema (id int, movie varchar(255), description varchar(255), rating float(2, 1))
Truncate table cinema
insert into cinema (id, movie, description, rating) values ('1', 'War', 'great 3D', '8.9')
insert into cinema (id, movie, description, rating) values ('2', 'Science', 'fiction', '8.5')
insert into cinema (id, movie, description, rating) values ('3', 'irish', 'boring', '6.2')
insert into cinema (id, movie, description, rating) values ('4', 'Ice song', 'Fantacy', '8.6')
insert into cinema (id, movie, description, rating) values ('5', 'House card', 'Interesting', '9.1')
思路分析:
找出影片为非boring,即description!=boring,
并且Id为奇数的影片,即id%2=1,结果按降序排列即排序order by rating desc。
画图分析:
代码实现:
select * from cinema
where description !='boring' and id%2=1
order by rating desc ;