使用工具sqldeveloper
請先參考 sqldeveloper下載及安裝及連線
測試資料來源請先參考 Oracle DB 目錄
用法說明:
關鍵詞(keyword): order by ASC DESC
order by 排序的關鍵詞
ASC 由小到大(預設)
DESC 由大到小
order by 欄位 ASC/DESC;
order by 欄位位置 ASC/DESC;
例:
此用 EMPLOYEES 資料表 來說明
依DEPARTMENT_ID排序,由小到大。
SELECT DISTINCT DEPARTMENT_ID FROM EMPLOYEES ORDER BY DEPARTMENT_ID ASC;
測試:
依DEPARTMENT_ID排序,由小到大。
SELECT DISTINCT DEPARTMENT_ID FROM EMPLOYEES ORDER BY DEPARTMENT_ID ;
測試:
依DEPARTMENT_ID排序,由大到小。
SELECT DISTINCT DEPARTMENT_ID FROM EMPLOYEES ORDER BY DEPARTMENT_ID DESC;
測試:
order by 欄位位置 ASC/DESC;
依DEPARTMENT_ID排序,由小到大。
SELECT FIRST_NAME, JOB_ID, SALARY, DEPARTMENT_ID FROM EMPLOYEES ORDER BY 4;
測試:
依DEPARTMENT_ID排序,由小到大。
SELECT FIRST_NAME, DEPARTMENT_ID FROM EMPLOYEES ORDER BY 2;
測試:
依DEPARTMENT_ID排序,由大到小。
SELECT FIRST_NAME, JOB_ID, DEPARTMENT_ID, SALARY FROM EMPLOYEES ORDER BY 3 DESC;
測試:
相關Oracle SQL用法教學
其它文章
沒有留言:
張貼留言