SELECT * FROM employees;
SELECT employee_id, first_name, last_name
FROM HR.employees;
SELECT employee_id, first_name, last_name
FROM employees
ORDER BY employee_id DESC;
SELECT job_id
FROM employees;
SELECT DISTINCT job_id
FROM employees;
SELECT employee_id AS 사원번호, first_name AS 이름, last_name AS 성
FROM HR.employees;
SELECT employee_id, first_name||last_name
FROM employees;
SELECT employee_id,
first_name||' '||last_name,
email||'@'||'company.com'
FROM HR.employees;
/* 문자형 변수로 쌍따옴표가 안되는 이유
alias에 공백을 두기 위해 사용하는 것이 쌍따옴표이고
문자열을 만들기 위한 따옴표와는 용도 자체가 다름 */
SELECT employee_id, salary, salary+500, salary-100, (salary*1.1)/2
FROM employees;
SELECT employee_id AS 사원번호,
salary AS 급여,
salary+500 AS 추가급여,
salary-100 AS 인하급여,
(salary*1.1)/2 AS 조정급여
FROM employees;
SELECT * FROM EMPLOYEES
WHERE EMPLOYEE_ID = 100;
SELECT * FROM EMPLOYEES
WHERE FIRST_NAME = 'David';
SELECT * FROM HR.EMPLOYEES
WHERE EMPLOYEE_ID >= 105;
SELECT * FROM EMPLOYEES
WHERE (EMPLOYEE_ID >= 150) AND (SALARY >= 5000);
SELECT * FROM EMPLOYEES
WHERE (FIRST_NAME = 'Lex') AND (SALARY >= 6000)
AND (HIRE_DATE >= '1999-01-01');
-- LABELING된 문자열을 >= 연산자로 비교
SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEES
WHERE (FIRST_NAME >= LAST_NAME);
-- BETWEEN 연산자: BETWEEN 이상 AND 이하
SELECT * FROM EMPLOYEES
WHERE SALARY BETWEEN 10000 AND 20000
ORDER BY SALARY DESC;
SELECT * FROM HR.EMPLOYEES
WHERE (SALARY >= 10000) AND (SALARY <= 20000);
-- IN 연산자: 조회하고자 하는 값이 여러 개일 때
SELECT * FROM HR.EMPLOYEES
WHERE (SALARY IN (10000, 17000, 24000));
SELECT * FROM HR.EMPLOYEES
WHERE (SALARY = 10000) OR (SALARY = 17000) OR (SALARY = 24000);
SELECT * FROM HR.EMPLOYEES
WHERE (LAST_NAME IN ('King', 'Tucker'));
-- LIKE 연산자: 조회 조건 값이 명확하지 않을 때 사용
SELECT * FROM HR.EMPLOYEES
WHERE JOB_ID LIKE 'AD%';
SELECT * FROM HR.EMPLOYEES
WHERE JOB_ID LIKE 'AD___';
SELECT SALARY FROM HR.EMPLOYEES
WHERE (SALARY LIKE '%500');
SELECT FIRST_NAME FROM HR.EMPLOYEES
WHERE FIRST_NAME LIKE '_e%';
-- IS NULL 연산자: 데이터 값이 null인 경우를 조회
SELECT * FROM EMPLOYEES
WHERE (MANAGER_ID IS NULL);
SELECT * FROM EMPLOYEES
WHERE NOT(MANAGER_ID IS NULL); -- IS NOT NULL과 동일
-- 논리 연산자: AND, OR, NOT
SELECT * FROM EMPLOYEES
WHERE SALARY > 4000 AND JOB_ID = 'IT_PROG';
SELECT * FROM EMPLOYEES
WHERE SALARY > 4000 AND JOB_ID = 'IT_PROG' OR JOB_ID = 'FI_ACCOUNT';
-- 중요: 괄호에 따른 연산 순서 및 결과의 차이 발생
SELECT LAST_NAME, JOB_ID, SALARY FROM EMPLOYEES
WHERE (JOB_ID = 'SA_REP' OR JOB_ID = 'AD_PRES') AND SALARY > 15000;
SELECT LAST_NAME, JOB_ID, SALARY FROM EMPLOYEES
WHERE JOB_ID = 'SA_REP' OR (JOB_ID = 'AD_PRES' AND SALARY > 15000);
-- 부정 비교/SQL 연산자: <>, !=, IS NOT NULL 등
SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID <> 105;
SELECT * FROM EMPLOYEES WHERE MANAGER_ID IS NOT NULL;
SELECT * FROM EMPLOYEES WHERE NOT(MANAGER_ID IS NULL