当前位置: 移动技术网 > IT编程>数据库>Mysql > NotBoringMovies--MOD()取余

NotBoringMovies--MOD()取余

2019年04月19日  | 移动技术网IT编程  | 我要评论

题目

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
;

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网