我們在尋找資料的同時也能用 ORDER BY 來排序資料
例如依照sal的值
query:
SELECT *
FROM emp
ORDER BY sal
EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
---|---|---|---|---|---|---|---|
7369 | SMITH | CLERK | 7902 | 1980/12/17 | 800 | - | 20 |
7900 | JAMES | CLERK | 7698 | 1981/12/03 | 950 | - | 30 |
7876 | ADAMS | CLERK | 7788 | 1983/01/12 | 1100 | - | 20 |
7654 | MARTIN | SALESMAN | 7698 | 1981/09/28 | 1250 | 1400 | 30 |
7521 | WARD | SALESMAN | 7698 | 1981/02/22 | 1250 | 500 | 30 |
7934 | MILLER | CLERK | 7782 | 1982/01/23 | 1300 | - | 10 |
7844 | TURNER | SALESMAN | 7698 | 1981/09/08 | 1500 | 0 | 30 |
7499 | ALLEN | SALESMAN | 7698 | 1981/02/20 | 1600 | 300 | 30 |
7782 | CLARK | MANAGER | 7839 | 1981/06/09 | 2450 | - | 10 |
7698 | BLAKE | MANAGER | 7839 | 1981/05/01 | 2850 | - | 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:
張貼留言