我正在尝试编写一个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 |
我的sql查询如下所示,但它似乎并没有按照评级顺序排列它们。谁能看到我做错了什么?
SELECT *
from cinema
WHERE ( id % 2 ) != 0
and description != 'boring'
ORDER BY rating ASC;
这是以错误的顺序返回电影。
答案 0 :(得分:2)
使用ORDER BY rating DESC
代替ASC
。
降序表示最高,升序表示最低。你想先获得高评价。