선택되는 행 제한
where 절을 사용한다.
BETWEEN, IN, LIKE
=, <>, >, <와 같은 비교 조건외에도 사용가능한 비교 조건들
LIKE 사용시에는 %, _와 같은 와일드카드 문자열을 사용한다.
% : 0개 이상의 임의의 문자열
_ : 1개의 임의의 문자열
ORDER BY
기본 정렬 조건은 오름차순(ASC)이다. 내림차순을 원할 경우 DESC를 표기해주어야 함.
select last_name, salary
from hr.employees
where salary > 12000;
select last_name, department_id
from hr.employees
where department_id = 176;
결과 없음 (사원 번호가 176인 튜플이 없음)
select last_name, salary
from hr.employees
where salary NOT Between 12000 AND 5000;
select last_name, department_id, hire_date
from hr.employees
where hire_date between TO_date('02-20-07', 'MM-DD-YY') and TO_date('05-01-07', 'MM-DD-YY')
order by hire_date;
select last_name, department_id
from hr.employees
where department_id in (20, 50)
order by last_name;
select last_name As "Employee", salary As "Monthly Salary"
from hr.employees
where salary Between 5000 AND 12000 AND department_id IN (20, 50);
select last_name, hire_date
from hr.employees
where hire_date between DATE '1994-01-01' and DATE '1994-12-31';
select last_name, job_id
from HR.employees
where manager_id IS NULL;
select last_name, salary, commission_pct
from hr.employees
where commission_pct is not null
order by salary desc, commission_pct desc;
select last_name
from HR.employees
where last_name like '__a%';
select last_name
from HR.employees
where last_name like ‘%a%’ AND last_name like ‘%e%’
SELECT last_name
from hr.employees
where last_name like '%a%e%' or last_name like '%e%a%’ 도 가능
select last_name, job_id, salary
from Hr.employees
where job_id in ('SA_REP', 'ST_CLERK') and salary not in (2500, 3500, 7000);
select last_name, salary, commission_pct
from hr.employees
where commission_pct = 0.2;
'CS > DB' 카테고리의 다른 글
[DB] ER 모델 (0) | 2022.05.14 |
---|---|
[DB] 데이터베이스 설계 개요 (0) | 2022.05.13 |
[DB] SQL 사용법(1) (0) | 2022.04.26 |
[DB] 관계 대수 예시 (0) | 2022.04.26 |
[DB] 관계 대수 (0) | 2022.04.26 |