采用降序排序-SQL语言基础

时间:2024-05-15 13:24:51
【文件属性】:

文件名称:采用降序排序-SQL语言基础

文件大小:5.26MB

文件格式:PPT

更新时间:2024-05-15 13:24:51

SQL 基础

采用降序排序 * SQL> SELECT ename, job, deptno, hiredate 2 FROM emp 3 ORDER BY hiredate DESC; ENAME JOB DEPTNO HIREDATE ---------- --------- --------- --------- ADAMS CLERK 20 12-JAN-83 SCOTT ANALYST 20 09-DEC-82 MILLER CLERK 10 23-JAN-82 JAMES CLERK 30 03-DEC-81 FORD ANALYST 20 03-DEC-81 KING PRESIDENT 10 17-NOV-81 MARTIN SALESMAN 30 28-SEP-81 ... 14 rows selected. * SELECT ename, job, deptno, hiredate FROM emp ORDER BY hiredate DESC; Default Ordering of Data The default sort order is ascending: Numeric values are displayed with the lowest values first—for example, 1–999. Date values are displayed with the earliest value first—for example, 01-JAN-92 before 01-JAN-95. Character values are displayed in alphabetical order—for example, A first and Z last. Null values are displayed last for ascending sequences and first for descending sequences. Reversing the Default Order To reverse the order in which rows are displayed, specify the keyword DESC after the column name in the ORDER BY clause. The slide example sorts the result by the most recently hired employee. Instructor Note Let the students know that you can also sort by a column number in the SELECT list. The example below will sort the output in the descending order by salary. SQL> SELECT ename, sal 2 FROM emp 3 ORDER BY 2 DESC;


网友评论