嗨,我有MySQL表看起来像这样......
+----+------+----------+------+
| id | name | priority | room |
+----+------+----------+------+
| 1 | AA | 2 | 507 |
| 2 | BB | 3 | 507 |
| 3 | CC | 1 | 405 |
| 4 | DD | 4 | 405 |
| 5 | EE | 6 | 205 |
| 6 | FF | 8 | 405 |
| 7 | GG | 7 | 205 |
| 8 | HH | 5 | 405 |
+----+------+----------+------+
我希望查询的结果看起来像这样..
+----+------+----------+------+
| id | name | priority | room |
+----+------+----------+------+
| 3 | CC | 1 | 405 |
| 4 | DD | 4 | 405 |
| 8 | HH | 5 | 405 |
| 6 | FF | 8 | 405 |
| 1 | AA | 2 | 507 |
| 2 | BB | 3 | 507 |
| 5 | EE | 6 | 205 |
| 7 | GG | 7 | 205 |
+----+------+----------+------+
我想订购房间的字段和优先级的字段
我尝试使用“ORDER BY priority,room”和“ORDER BY room,priority”但不起作用..
有人可以帮忙吗?请...谢谢
答案 0 :(得分:1)
尝试使用此查询:
SELECT id, name, priority, room
FROM table
ORDER BY room DESC, priority
默认排序顺序是升序,首先是最小值。要按反向(降序)排序,请将DESC关键字添加到要排序的列的名称
因此,您需要将DESC
添加到room
列,但不需要priority
列的修饰符。
答案 1 :(得分:0)
以下查询将根据您请求的结果给出结果。
SELECT `id`,`name`,`priority`,`room`
FROM table_name
ORDER BY `room` DESC;