-- 기본 순서
/*
SELECT 컬럼
FROM 테이블 OR SUB QUERY
WHERE 조건
GROUP BY
HAVING
ORDER BY 정렬 (오름,내림)
*/
-- HR
/*
ORDER BY == 정렬(SORT)
오름/내림
*/
-- 오름
SELECT FIRST_NAME,SALARY
FROM EMPLOYEES
ORDER BY SALARY;
-- 내림
SELECT FIRST_NAME,SALARY
FROM EMPLOYEES
ORDER BY SALARY DESC;
-- IT_PROG 중 월급 내림차순
SELECT FIRST_NAME, JOB_ID , SALARY
FROM EMPLOYEES
WHERE JOB_ID = 'IT_PROG'
ORDER BY SALARY DESC;
-- MANAGER_ID 가 NULL 인사람을 첫번째로
SELECT EMPLOYEE_ID, FIRST_NAME, SALARY, MANAGER_ID
FROM EMPLOYEES
ORDER BY MANAGER_ID NULLS FIRST;
-- MANAGER_ID 가 NULL 인사람을 첫번째로
-- SALARY 를 내림차순으로
SELECT EMPLOYEE_ID, FIRST_NAME, SALARY, MANAGER_ID
FROM EMPLOYEES
ORDER BY MANAGER_ID NULLS FIRST, SALARY DESC;
-- 엘리어스? 를 사용해서도 가능
SELECT FIRST_NAME,SALARY * 12 AS 연봉
FROM EMPLOYEES
ORDER BY 연봉 DESC;
'Oracle Database > SQL' 카테고리의 다른 글
SQL 쿼리문 기본 (0) | 2018.06.26 |
---|---|
SQL 쿼리 그룹 (0) | 2018.06.26 |
SQL명령어 (0) | 2018.06.26 |
Oracle Database 사용방법 및 주석 (0) | 2018.06.20 |
Oracle Database (SELECT - WHERE)문 (0) | 2018.06.20 |