select → where (조건식)
-- 급여가 1500보다 크거나 같은 데이터를 조회.
select * from employee where salary >= 1500;
-- 스콧의 이름을 가지고 있는 데이터를 조회.
select * from employee where enmae = 'scotte';
-- 입사날짜가 1981-01-01 이전의 데이터를 조회
select *from employee where hirdate < '1981-01-01';
-- 이름, 급여, 연봉 테이터를 조회
select ename, salary, salary * 12 from employee;
-- 이름, 급여, 연봉(as를 써줌으로써 연봉으로 변경) 테이터를 조회
select ename, salary, salary * 12 as 연봉 from employee;
-- 부서 넘버가 10인 사원과, 직무가 매니저인 사원의 테이터를 조회
select * from employee where dno =10 and job = 'manager';
not = ><
-- 부서번호가 10번이 아닌 데이터를 조회.
select * from employee where not dno = 10;
select * from employee where dno >< 10;
% 쓸 때는 like연자가 꼭 필요!
-- 에러
select * from employee where ename= '%m%';
-- m을 포함하고 있는 이름
select * from employee where ename like %m%;
-- m이 3번째로 나오는 이름
select * from employee where ename like %__m%;
NULL 쓸 때는 IS가 꼭 필요!
-- 에러
select * from employee where commission = null;
-- 커미션이 null인 사원
select * from employee where commission is null;
-- 커미션이 null이 아닌 사원
select * from employee where commission is not null;
ORDER BY : 정렬
-- 급여 내림차순으로 데이터를 조회
select * from employee order by salary desc;
**문제 1)
급여가 2000~3000사이에 포함되고, 부서 번호가 20 또는 30인 사원의 이름, 급여와 부서번호를 출력하되, 급여 내림차순으로 출려하시오
select ename, salary, dno from employee where salary between 2000 and 3000
and dno in(20, 30) order by salary desc;
**문제 2)
1981년도에 입사한 사원들의 이름과 입사일을 출려하시오.(와일드카드(%)를 사용)
select ename, hiredate from employee where hiredate like %1981%;
**문제 3)
이름에 A와E를 모두 포함하고 있는 사원들의 정보를 출력하시오.
select * from employee where ename like %a% and ename like %e%;728x90