我希望这不是一个重复的问题。是否可以按如下方式对表格进行排序?我正在尝试按升序排列position
和checked
两列。
+----------+----------+---------+
| item | position | checked |
+----------+----------+---------+
| apple | 1 | 0 |
| banana | 5 | 0 |
| coconut | 2 | 1 |
| dog | 0 | 0 |
| elephant | 4 | 1 |
| fox | 3 | 0 |
+----------+----------+---------+
+----------+----------+---------+
| item | position | checked |
+----------+----------+---------+
| dog | 0 | 0 |
| apple | 1 | 0 |
| fox | 3 | 0 |
| banana | 5 | 0 |
| coconut | 2 | 1 |
| elephant | 4 | 1 |
+----------+----------+---------+
我尝试使用以下查询。
SELECT * FROM items ORDER BY position AND checked;
但是,这只能按一列排序。
+----------+----------+---------+
| item | position | checked |
+----------+----------+---------+
| apple | 1 | 0 |
| banana | 5 | 0 |
| dog | 0 | 0 |
| fox | 3 | 0 |
| coconut | 2 | 1 |
| elephant | 4 | 1 |
+----------+----------+---------+
我尝试使用ASC
和逗号代替AND
,依此类推,但都没有效果。这甚至可能吗?
修改 我尝试了gvee的解决方案,这就是我得到的。
+----------+----------+---------+
| item | position | checked |
+----------+----------+---------+
| dog | 0 | 0 |
| apple | 1 | 0 |
| coconut | 2 | 1 |
| fox | 3 | 0 |
| elephant | 4 | 1 |
| banana | 5 | 0 |
+----------+----------+---------+
答案 0 :(得分:4)
....
ORDER
BY checked ASC
, position ASC