방대한 데이터의 세계로, JUST DO DBMS!
select 속성이름(들)
from 테이블이름(들)
where 조건 = '조건'
; -- 세미콜론으로 명령어 종료
SELECT *
FROM EMPLOYEES e ;
SELECT employee_id, last_name
FROM EMPLOYEES e ;
SELECT EMPLOYEE_ID,
EMAIL,
HIRE_DATE,
SALARY ,
COMMISSION_PCT
FROM EMPLOYEES e ;
SELECT EMPLOYEE_ID ,
LAST_NAME
FROM EMPLOYEES e
WHERE JOB_ID = 'SA_REP'
;
SELECT EMPLOYEE_ID AS "ID",
SALARY AS "SAL"
FROM EMPLOYEES e
;
SELECT EMPLOYEE_ID "ID", -- AS의 생략이 가능하다.
SALARY "SAL"
FROM EMPLOYEES e -- e는 EMPLOYEES 의 알리아스, 별칭이다. 여러 테이블을 가지고 올 때 필요하다.
;
SELECT DISTINCT DEPARTMENT_ID
FROM EMPLOYEES e
;
SELECT *
FROM EMPLOYEES e
;
SELECT *
FROM EMPLOYEES e
WHERE DEPARTMENT_ID = 50
OR MANAGER_ID = 100
;
SELECT *
FROM EMPLOYEES e
WHERE NOT DEPARTMENT_ID = 50
;
SELECT *
FROM EMPLOYEES e
WHERE DEPARTMENT_ID <> 50
;
SELECT *
FROM EMPLOYEES e
WHERE DEPARTMENT_ID != 50
;
SELECT *
FROM EMPLOYEES e
WHERE SALARY >= 4000 AND SALARY <= 8000
;
SELECT *
FROM EMPLOYEES e
WHERE SALARY BETWEEN 4000 AND 8000
;
-- OR와 동일한 역할을 한다.
SELECT *
FROM EMPLOYEES e
WHERE SALARY = 6500
OR SALARY = 7700
OR SALARY = 13000
;
SELECT *
FROM EMPLOYEES e
WHERE SALARY IN (6500, 7700, 13000)
;
-- D로 시작하는 사람
SELECT FIRST_NAME ,
LAST_NAME
FROM EMPLOYEES e
WHERE FIRST_NAME LIKE 'D%'
;
-- 'd' 로 끝나는 사람
SELECT FIRST_NAME,
LAST_NAME
FROM EMPLOYEES e
WHERE FIRST_NAME LIKE '%d'
;
--세번 째 글자가 a인 사람
SELECT FIRST_NAME,
LAST_NAME
FROM EMPLOYEES e
WHERE FIRST_NAME LIKE '__a%'
;
SELECT *
FROM EMPLOYEES e
WHERE COMMISSION_PCT IS NULL
;
-- null 이 아닌 것
SELECT *
FROM EMPLOYEES e
WHERE COMMISSION_PCT IS NOT NULL
;
-- ORDER BY의 기본 속성은 오름차순이여서, ASC는 생략가능
SELECT *
FROM EMPLOYEES e
ORDER BY SALARY ASC
-- ORDER BY SALARY 위와 동일하다.
;
SELECT *
FROM EMPLOYEES e
ORDER BY SALARY DESC
;
-- 해당 데이터의 합
SELECT SUM(SALARY)
FROM EMPLOYEES e
;
-- 해당 데이터 갯수 가져오기
SELECT COUNT(*)
FROM EMPLOYEES e
;
SELECT COUNT(EMPLOYEE_ID) "CNT"
FROM EMPLOYEES e
;
-- 해당 데이터의 평균
SELECT AVG(SALARY)
FROM EMPLOYEES e
;
SELECT AVG(SALARY)
FROM EMPLOYEES e
WHERE DEPARTMENT_ID = 80
;
-- 해당 데이터의 최대값
SELECT MAX(SALARY)
FROM EMPLOYEES e
;
SELECT MAX(HIRE_DATE)
FROM EMPLOYEES e
;
-- 해당 데이터의 최소값
SELECT MIN(SALARY)
FROM EMPLOYEES e
;
SELECT MIN(HIRE_DATE)
FROM EMPLOYEES e
;
출처
https://media.giphy.com/media/1hVi7JFFzplHW/giphy.gif
https://media.giphy.com/media/jUwpNzg9IcyrK/giphy.gif
https://ko.dict.naver.com/#/entry/koko/1dde70640cda4f8692a8e940957aba2b