Oracle ORDER BY

 我們在尋找資料的同時也能用 ORDER BY 來排序資料


例如依照sal的值

query:

SELECT *

FROM emp

ORDER BY sal


EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7369SMITHCLERK79021980/12/17800-20
7900JAMESCLERK76981981/12/03950-30
7876ADAMSCLERK77881983/01/121100-20
7654MARTINSALESMAN76981981/09/281250140030
7521WARDSALESMAN76981981/02/22125050030
7934MILLERCLERK77821982/01/231300-10
7844TURNERSALESMAN76981981/09/081500030
7499ALLENSALESMAN76981981/02/20160030030
7782CLARKMANAGER78391981/06/092450-10
7698BLAKEMANAGER78391981/05/012850-30


加入DESC也可以降冪排列

query:

SELECT *

FROM emp

ORDER BY sal DESC


加入ASC是升冪排列

SELECT *

FROM emp

ORDER BY SAL ASC



ORDER BY 也可以使用多個column

SELECT DEPTNO, SAL, ENAME

FROM EMP

ORDER BY DEPTNO, SAL

0 Comments:

張貼留言