1. ORDER BY 정렬
1 2 3 4 5 6
| SELECT 칼럼명 [ALIAS명] FROM 테이블명 [WHERE 조건식] [GROUP BY 칼럼또는 표현식] [HAVING 그룹조건식] [ORDER BY 칼럼이나 표현식 [ASC 또는 DESC];
|
2.SELECT 문장실행 순서
5)SELECT
1)FROM
2)WHERE
3)GROUP BY
4)HAVING
6)ORDER BY
1 2 3 4 5 6 7 8
| SELECT DNAME, LOC, DEPTNO FROM DEPT ORDER BY 1,2,3 DESC;
SELECT JOB FROM EMP GROUP BY JOB HAVING COUNT(*)>0 ORDER BY MAX(EMPNO), MAX(MGR), SUM(SAL), COUNT(DEPTNO), MAX(HIREDATE);
|
3. TOP N 쿼리
ROWNUM
1 2 3 4 5 6 7 8 9 10
| SELECT ENAME, SAL FROM EMP WHERE ROWNUM <4 ORDER BY SAL;
SELECT ENAME, SAL FROM (SELECT ENAME, SAL FROM EMP ORDER BY SAL DESC) WHERE ROWNUM<4;
|