我希望这不是一个重复的问题。是否可以对如下表进行排序?我正在尝试按两列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 逗号代替AND
, 等等,但它们都不起作用。这甚至可能吗?
编辑 我尝试了 gvee 的解决方案,这就是我得到的。
+----------+----------+---------+
| item | position | checked |
+----------+----------+---------+
| dog | 0 | 0 |
| apple | 1 | 0 |
| coconut | 2 | 1 |
| fox | 3 | 0 |
| elephant | 4 | 1 |
| banana | 5 | 0 |
+----------+----------+---------+