MariaDB [hello]> select ename,sal from emp order by 2; +--------+---------+ | ename | sal | +--------+---------+ | SMITH | 800.00 | | JAMES | 950.00 | | ADAMS | 1100.00 | | WARD | 1250.00 | | MARTIN | 1250.00 | | MILLER | 1300.00 | | TURNER | 1500.00 | | ALLEN | 1600.00 | | CLARK | 2450.00 | | BLAKE | 2850.00 | | JONES | 2975.00 | | FORD | 3000.00 | | SCOTT | 3000.00 | | KING | 5000.00 | +--------+---------+ 14 rows in set (0.001 sec)
在上述代码块中,2表示第二列,第二列是sal。
按照查询结果的第二列sal进行排序。
(仅供了解,不建议在开发中这样写。因为列的顺序很容易发生改变)
综合案例
找出工资在1250到3000之间的员工信息,要求按照薪资降序排列。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
MariaDB [hello]> select ename,sal from emp where sal between 1250 and 3000 order by sal desc; +--------+---------+ | ename | sal | +--------+---------+ | FORD | 3000.00 | | SCOTT | 3000.00 | | JONES | 2975.00 | | BLAKE | 2850.00 | | CLARK | 2450.00 | | ALLEN | 1600.00 | | TURNER | 1500.00 | | MILLER | 1300.00 | | MARTIN | 1250.00 | | WARD | 1250.00 | +--------+---------+ 10 rows in set (0.001 sec)