NotBoringMovies--MOD()取余
程序员文章站
2022-06-15 12:03:34
题目
x city opened a new cinema, many people would like to go to this cinema. the cinema al...
题目
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.
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.
for example, table 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 | +---------+-----------+--------------+-----------+for the example above, the output should be:
+---------+-----------+--------------+-----------+ | id | movie | description | rating | +---------+-----------+--------------+-----------+ | 5 | house card| interesting| 9.1 | | 1 | war | great 3d | 8.9 | +---------+-----------+--------------+-----------+
approach: using mod() function [accepted]
algorithm
we can use the mod(id,2)=1 to determine the odd id, and then add a description != 'boring' should address this problem.
mysql
select * from cinema where mod(id, 2) = 1 and description != 'boring' order by rating desc ;
上一篇: 饮食需节制 自倍易伤肠胃
下一篇: 使用springMVC所需要的pom配置