ORDER BY不执行任何功能

时间:2017-10-19 19:56:14

标签: mysql

我已经为下面的问题写了一个SQL查询。它工作正常,但ORDER BY不工作,结果不是降序。请建议它是如何工作的。

问题:

编写一个SQL查询来输出具有奇数编号ID和非“无聊”描述的电影。通过评级订购结果。

例如,桌上电影院:

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

查询:

SELECT id,movie,description,rating
FROM cinema
WHERE cinema.id%2!=0
AND cinema.description != "boring"
ORDER BY cinema.id DESC;

1 个答案:

答案 0 :(得分:3)

您只需将ORDER BY条款更改为rating列的订单:

SELECT id,movie,description,rating
FROM cinema
WHERE cinema.id%2!=0
AND cinema.description != "boring"
ORDER BY cinema.rating DESC