我已经为下面的问题写了一个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;
答案 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