【文件属性】:
文件名称:按照多个列进行排序-SQL语言基础
文件大小:5.26MB
文件格式:PPT
更新时间:2021-04-25 19:38:12
SQL 基础
按照多个列进行排序
*
可以按照 SELECT 列中没有的列来进行排序.
SQL> SELECT ename, deptno, sal
2 FROM emp
3 ORDER BY deptno, sal DESC;
ENAME DEPTNO SAL
---------- --------- ---------
KING 10 5000
CLARK 10 2450
MILLER 10 1300
FORD 20 3000
...
14 rows selected.
ORDER BY 后的列的顺序既排序的顺序.
*
SELECT ename, deptno, sal
FROM emp
ORDER BY deptno, sal DESC;
Sorting by Multiple Columns
You can sort query results by more than one column. The sort limit is the number of columns in the given table.
In the ORDER BY clause, specify the columns, and separate the column names using commas. If you want to reverse the order of a column, specify DESC after its name. You can order by columns that are not included in the SELECT clause.
Example
Display name and salary of all employees. Order the result by department number and then descending order by salary.
Instructor Note
Show that the DEPTNO column is sorted in ascending order and the SAL column in descending order.
SQL> SELECT ename, sal
2 FROM emp
3 ORDER BY deptno, sal DESC;