sqlplus ora1/oracle_4U@localhost:1521/xepdb1
conn ora1/oracle_4U@localhost:1521/xepdb1
@C:\adsql_labs\ํ์ผ๋ช
-- 3day ๋ณต์ต ๋ฌธ์ SOL
--1. ์ฌ์์ด๋ฆ, ์๊ธ, ์ปค๋ฏธ์
, ์๋ น์ก(์๊ธ + ์ปค๋ฏธ์
)์ ์ถ๋ ฅํ์์ค.
-- (์๋ น์ก ๊ณ์ฐ์ ์ปค๋ฏธ์
์ด ์ ์ฉ๋์ง ์๋ ์ฌ์์ ๊ฒฝ์ฐ๋ ์ปค๋ฏธ์
์
-- ์ผ๊ด์ ์ผ๋ก 100์ ์ ์ฉํฉ๋๋ค.)
select ename, sal, comm, sal+nvl(comm,100)
from emp;
--2. ์ด๋ฆ, ์ปค๋ฏธ์
์ ์ถ๋ ฅํ๋๋ฐ ์ปค๋ฏธ์
์ด null ์ธ ์ฌ์๋ค์ no comm ์ด๋
-- ๋ฌธ์์ด๋ก ์ถ๋ ฅ๋๊ฒํ์์ค.
select ename, nvl(to_char(comm),'no_comm') comm
from emp;
--3. ์ด๋ฆ, ์
์ฌํ ๋
๋(4์๋ฆฌ), ์๊ธ, ๋ณด๋์ค๋ฅผ ์ถ๋ ฅํ๋๋ฐ
-- ๋ณด๋์ค๊ฐ ์
์ฌํ ๋
๋๊ฐ 1981 ๋
๋๋ฉด 5000 ์ ์ถ๋ ฅํ๊ณ
-- ๋๋จธ์ง ์ฌ์๋ค์ 0 ์ ์ถ๋ ฅํ์์ค.
select ename, to_char(hiredate,'RRRR'), sal,
decode( to_char(hiredate,'RRRR'),'1981', 5000, 0) ๋ณด๋์ค
from emp;
--
select ename, to_char(hiredate,'RRRR'), sal,
CASE WHEN to_char(hiredate,'RRRR') = '1981' THEN 5000
ELSE 0
END ๋ณด๋์ค
from emp;
--
select ename, to_char(hiredate,'RRRR'), sal,
case to_char(hiredate,'RRRR')
when '1981' then 5000
else 0 end ๋ณด๋์ค
from emp;
--4. ์ด๋ฆ, ์๊ธ๊ณผ ๋ณด๋์ค๋ฅผ ์ถ๋ ฅํ๋๋ฐ
-- ์๊ธ์ด 3000 ์ด์์ด๋ฉด ๋ณด๋์ค๋ฅผ 6000 ์ ์ถ๋ ฅํ๊ณ
-- ์๊ธ์ด 3000 ๋ณด๋ค ์์ผ๋ฉด ๋ณด๋์ค๋ฅผ 0 ์ ์ถ๋ ฅํ์์ค.
select ename, sal,
case when sal >= 3000 then 6000
else 0 end as bonus
from emp;
--5. ์ด๋ฆ, ์ปค๋ฏธ์
, ๋ณด๋์ค๋ฅผ ์ถ๋ ฅํ๋๋ฐ ๋ณด๋์ค๊ฐ
-- ์ปค๋ฏธ์
์ด null ์ด๋ฉด 7000 ์ ์ถ๋ ฅํ๊ณ
-- ์ปค๋ฏธ์
์ด null ์ด ์๋๋ฉด 0 ์ ์ถ๋ ฅํ์์ค.
select ename, comm,
case when comm is null then 7000
else 0 end as bonus
from emp;
--6. ์ด๋ฆ, ์๊ธ , ์ง์
, ๋ณด๋์ค๋ฅผ ์ถ๋ ฅํ๋๋ฐ
-- ์ง์
์ด SALESMAN ์ด๊ณ ์๊ธ์ด 1000 ์ด์์ด๋ฉด ๋ณด๋์ค๋ฅผ 9000 ์ ์ถ๋ ฅํ๊ณ
-- ์ง์
์ด ANALYST ์ด๊ณ ์๊ธ์ด 2500 ์ด์์ด๋ฉด ๋ณด๋์ค๋ฅผ 8000 ์ ์ถ๋ ฅํ๊ณ
-- ๋๋จธ์ง ์ฌ์๋ค์ 0 ์ ์ถ๋ ฅํ์์ค.
select ename, sal, job,
case when ( job='SALESMAN' and sal >= 1000) then 9000
when ( job='ANALYST' and sal >= 2500) then 8000
else 0 end as bonus
from emp;
--7. ๋ถ์๋ฒํธ, ๋ถ์๋ฒํธ๋ณ ์ต๋์๊ธ์ ์ถ๋ ฅํ๋๋ฐ
-- ๋ถ์๋ฒํธ๋ณ ์ต๋์๊ธ์ด ๋์๊ฒ ๋ถํฐ ์ถ๋ ฅํ์์ค.
select deptno, max(sal)
from emp
group by deptno
order by max(sal) desc;
--8. ์์ ๊ฒฐ๊ณผ์์ ๋ถ์๋ฒํธ 20๋ฒ์ ์ ์ธํ๊ณ ์ถ๋ ฅํ์์ค.
-- ๋ถ์๋ฒํธ 20์ด ์๋ ๊ฒ๋ค์ ์ ๋ณํด ๊ทธ๋ฃนํ
select deptno, max(sal)
from emp
where deptno !=20
group by deptno
order by max(sal) desc;
-- ์๋ HAVING ์ ์ ์คํ ์์๊ฐ WHERE๊ณผ ์์ดํ ์ ์ ์ ์
-- ๊ทธ๋ฃนํํ ํ ๋ถ์๋ฒํธ 20์ด ์๋ ๊ฒ๋ค์ ์ ์ธ
select deptno, max(sal)
from emp
--where deptno !=20
group by deptno
HAVING DEPTNO !=20
order by max(sal) desc;
--9. ์ง์
, ์ง์
๋ณ ํ ํ์๊ธ์ ์ถ๋ ฅํ๋๋ฐ
-- ์ง์
์ด SALESMAN ์ธ ์ฌ์๋ค์ ์ ์ธํ๊ณ ์ถ๋ ฅํ๊ณ
-- ์ง์
๋ณ ํ ํ์๊ธ์ด ๋์๊ฒ๋ถํฐ ์ถ๋ ฅํ๋๋ฐ
-- ์ง์
๋ณ ํ ํ์๊ธ์ ์ถ๋ ฅํ ๋์ ์ฒ๋จ์๋ฅผ ๋ถ์ฌํด์
-- ์ถ๋ ฅํ์์ค.
select job, to_char(sum(sal),'99,999') "SUM(SAL)"
from emp
where job != 'SALESMAN'
group by job
order by sum(sal) desc;
--10. ๋ถ์๋ฒํธ, ๋ถ์๋ฒํธ๋ณ ํ ํ์๊ธ์ ์ถ๋ ฅํ์์ค.
--
select deptno, sum(sal)
from emp
group by deptno;
--11. ์์ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ๋ก๋ก ์ถ๋ ฅํ์์ค.
--
--
-- ์ด ๋ฌธ์ ๋ emp ํ
์ด๋ธ์ ๋ถ์๋ฒํธ๊ฐ 10๋ฒ 20๋ฒ 30๋ฒ์ด
-- ์๋ค๋๊ฒ์ ์๋ค๋ผ๋ ๊ฐ์ ํ์ SQL ์ ์์ฑํ๋ฉด ๋จ
select sum(decode(deptno,10,sal,0)) "10",
sum(decode(deptno,20,sal,0)) "20",
sum(decode(deptno,30,sal,0)) "30"
from emp;
--12. ์ง์
, ๋ถ์๋ฒํธ, ์ง์
๋ณ ๋ถ์๋ฒํธ๋ณ ํ ํ์๊ธ์ ์ถ๋ ฅํ์์ค.
select job,
sum(decode(deptno,10,sal)) as "10",
sum(decode(deptno,20,sal)) as "20",
sum(decode(deptno,30,sal)) as "30"
from emp
group by job;
--1)
SELECT E.EMPLOYEE_ID, E.DEPARTMENT_ID, D.DEPARTMENT_ID, D.LOCATION_ID
FROM EMPLOYEES E JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID;
--2)
SELECT D.DEPARTMENT_ID, D.DEPARTMENT_NAME, L.CITY
FROM DEPARTMENTS D JOIN LOCATIONS L
ON D.LOCATION_ID = L.LOCATION_ID
WHERE DEPARTMENT_ID IN (20, 50);
SELECT *
FROM LOCATIONS;
--3)
SELECT E.LAST_NAME, D.DEPARTMENT_NAME, L.CITY
FROM EMPLOYEES E JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
JOIN LOCATIONS L
ON D.LOCATION_ID = L.LOCATION_ID;
--4)
SELECT E1.LAST_NAME E_NAME, E2.LAST_NAME M_NAME
FROM EMPLOYEES E1
JOIN EMPLOYEES E2
ON E1.EMPLOYEE_ID = E2.MANAGER_ID;
--5)
SELECT E.LAST_NAME, E.DEPARTMENT_ID, D.DEPARTMENT_NAME
FROM EMPLOYEES E
LEFT OUTER JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID;
--6)
SELECT D.DEPARTMENT_ID, E.LAST_NAME, E.SALARY
FROM EMPLOYEES E
JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID;
--7)
SELECT D.DEPARTMENT_ID, E.LAST_NAME, E.SALARY
FROM EMPLOYEES E
RIGHT OUTER JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
AND SALARY >= 10000
ORDER BY DEPARTMENT_ID;
-- WHERE, AND ์ฐจ์ด -> ๋ช
๋ น์ด ์ฒ๋ฆฌ ์์๊ฐ OUTER ์กฐ์ธ ๋จผ์ , ํํฐ๋ง ์งํ (๋ถ์์ ๋ํ ๋ด์ฉ์ด ํํฐ๋ง)
-- AND ์ฐ์ฐ ์ ์กฐ๊ฑด ์คํ ํ OUTER JOIN ์คํ
--8) ๋น์กฐ์ธ ์กฐ๊ฑด์ผ๋ก ๋ค์ ํ๊ธฐ
SELECT E.LAST_NAME, E.JOB_ID, D.DEPARTMENT_ID, D.DEPARTMENT_NAME
FROM EMPLOYEES E
JOIN DEPARTMENTS D
ON E.DEPARTMENT_ID = D.DEPARTMENT_ID
JOIN LOCATIONS L
ON D.LOCATION_ID = L.LOCATION_ID
WHERE L.CITY = 'Toronto';
--9)
SELECT E1.LAST_NAME "EMPLOYEE", E1.EMPLOYEE_ID "EMP#", E2.LAST_NAME, E2.MANAGER_ID "Mgr#"
FROM EMPLOYEES E1
LEFT OUTER JOIN EMPLOYEES E2
ON E1.MANAGER_ID = E2.EMPLOYEE_ID;
--10) ๋น์กฐ์ธ ์กฐ๊ฑด
SELECT E.LAST_NAME, E.JOB_ID, D.DEPARTMENT_NAME, E.SALARY, J.GRADE_LEVEL
FROM EMPLOYEES E , DEPARTMENTS D , JOB_GRADES J
WHERE E.DEPARTMENT_ID = D.DEPARTMENT_ID
AND E.SALARY
BETWEEN J.LOWEST_SAL AND J.HIGHEST_SAL;
-- ๋น์กฐ์ธ ์กฐ๊ฑด์ ๋ฐ๋์ AND๋ก ์ฐ๊ฒฐํด์ผํจ (WHERE์ ์๋จ)
--11) ??
@C:\ADSQL_labs\emp_kind
select e.empno, e.ename, e.emp_kind, k1.office_sal, k2.sal
from emp_kind e, emp_kind1 k1, emp_kind2 k2
where e.empno=k1.empno(+)
and e.empno=k2.empno(+)
order by e.emp_kind;
--12) ๋ชจ๋ฅด๊ฒ ์ -> ์
ํ ์กฐ์ธ์ผ๋ก ํด๊ฒฐ (+. ๋น๋๋ฑ ์กฐ์ธ ํ์ฉ)
SELECT E.EMPNO, E.ENAME, E.SAL, J.SAL "JONES SALARY"
FROM EMP E
JOIN EMP J
ON E.EMPNO = J.EMPNO
WHERE E.SAL > J.SAL ;
select e.empno, e.ename, e.sal, j.sal as "Jones's Salary"
from emp e, emp j
where upper(j.ename)='JONES'
and j.sal < e.sal;
--13) ๋ชจ๋ฅด๊ฒ ์
SELECT DISTINCT(D.DEPTNO) DEPTNO, D.DNAME, D.LOC,
CASE WHEN ENAME IS NOT NULL THEN 'YES' ELSE 'NO' END EMP
FROM DEPT D
LEFT OUTER JOIN EMP E
ON D.DEPTNO = E.DEPTNO;
--SOL
select d.deptno, d.dname, d.loc, decode(count(e.deptno),0,'NO','YES') as emp
from dept d, emp e
where d.deptno=e.deptno(+)
group by d.deptno, d.dname, d.loc
order by d.deptno
--14) ๋ชจ๋ฅด๊ฒ ์
SELECT E.FIRST_NAME, E.LAST_NAME, E.SALARY, E.JOB_ID, C.COUNTRY_NAME
FROM EMPLOYEES E , countries C
WHERE COUNTRY_NAME = 'Canada'
AND E.SALARY BETWEEN >= 6000 AND <= 13000;
--SOL ์ง๊ฒ๋ค๋ฆฌ ํ
์ด๋ธ (4๊ฐ ํ
์ด๋ธ ์กฐ์ธ ํ) E, Dํ
์ด๋ธ ๊ฐ ์ฐ๊ฒฐ๊ณ ๋ฆฌ๋ก์ L,C ์กฐ์ธ ์ํ (ERD ์ฐธ๊ณ )
select e.first_name, e.last_name, e.salary, e.job_id, c.country_name
from employees e,
departments d
, locations l
, countries c
where e.department_id=d.department_id
and d.location_id=l.location_id
and l.country_id=c.country_id
and initcap(c.country_name)='Canada';
--15) ๋ชจ๋ฅด๊ฒ ์
-- GROUP BY ํ์๋ SELECT ์ ์ ์ธ๊ธ๋ ๋ชจ๋ ์์ฑ (P.PROD_ID, P.PROD_NAME) ๊ธฐ์
ํ
SELECT P.PROD_ID, P.PROD_NAME, SUM(S.QUANTITY_SOLD) SOLD_SUM
FROM PRODS P
LEFT OUTER JOIN SALES S
ON P.PROD_ID = S.PROD_ID
GROUP BY P.PROD_ID, P.PROD_NAME;
--SOL
select p.prod_id, p.prod_name, sum(s.quantity_sold) as sold_sum
from prods p, sales s
where p.prod_id=s.prod_id(+)
group by p.prod_id, p.prod_name;
๐ฝ 3DAY_2
--1
SELECT e.employee_id, e.last_name, e.department_id,
d.department_id, d.location_id
FROM employees e , departments d
WHERE e.department_id = d.department_id;
SELECT e.employee_id, e.last_name, e.department_id,
d.department_id, d.location_id
FROM employees e JOIN departments d
ON e.department_id = d.department_id;
--2
SELECT d.department_id, d.department_name, l.city
FROM departments d, locations l
WHERE d.location_id = l.location_id
AND d.department_id IN (20, 50);
SELECT d.department_id, d.department_name, l.city
FROM departments d JOIN locations l
ON d.location_id = l.location_id
AND d.department_id IN (20, 50);
--3
SELECT e.last_name, d.department_name, l.city
FROM employees e , departments d, locations l
WHERE e.department_id = d.department_id
AND d.location_id = l.location_id;
SELECT e.last_name, d.department_name, l.city
FROM employees e JOIN departments d
ON e.department_id = d.department_id
JOIN locations l
ON d.location_id = l.location_id;
--4
SELECT e.last_name e_name, m.last_name m_name
FROM employees e , employees m
WHERE e.manager_id=m.employee_id;
SELECT e.last_name e_name, m.last_name m_name
FROM employees e JOIN employees m
ON e.manager_id=m.employee_id;
--5
SELECT e.last_name, e.department_id, d.department_name
FROM employees e, departments d
WHERE e.department_id = d.department_id(+) ;
SELECT e.last_name, e.department_id, d.department_name
FROM employees e LEFT OUTER JOIN departments d
ON e.department_id = d.department_id ;
--6
SELECT d.department_id, e.last_name, e.salary
FROM employees e, departments d
WHERE e.department_id(+) = d.department_id;
SELECT d.department_id, e.last_name, e.salary
FROM employees e RIGHT OUTER JOIN departments d
ON e.department_id = d.department_id;
--7
SELECT d.department_id, e.last_name, e.salary
FROM employees e, departments d
WHERE e.department_id(+) = d.department_id
and e.salary(+) > 10000;
SELECT d.department_id, e.last_name, e.salary
FROM employees e RIGHT OUTER JOIN departments d
ON e.department_id = d.department_id
and e.salary > 10000;
--8
SELECT e.last_name, e.job_id, e.department_id, d.department_name
FROM employees e, departments d, locations l
WHERE e.department_id=d.department_id
AND d.location_id=l.location_id
AND lower(l.city)='toronto';
SELECT e.last_name, e.job_id, e.department_id, d.department_name
FROM employees e JOIN departments d
ON e.department_id=d.department_id
JOIN locations l
ON d.location_id=l.location_id
AND lower(l.city)='toronto';
--9
SELECT e.last_name "Employee", e.employee_id "EMP#",
m.last_name "Manager", m.employee_id "Mgr#"
FROM employees e, employees m
WHERE e.manager_id=m.employee_id(+);
SELECT e.last_name "Employee", e.employee_id "EMP#",
m.last_name "Manager", m.employee_id "Mgr#"
FROM employees e LEFT OUTER JOIN employees m
ON e.manager_id=m.employee_id;
--10
SELECT e.LAST_NAME, e.job_id, d.department_name,
e.salary, j.grade_level
FROM employees e, departments d, job_grades j
WHERE e.department_id=d.department_id
AND e.salary between j.lowest_sal and j.highest_sal;
SELECT e.LAST_NAME, e.job_id, d.department_name,
e.salary, j.grade_level
FROM employees e JOIN departments d
ON e.department_id=d.department_id
JOIN job_grades j
ON e.salary between j.lowest_sal and j.highest_sal;
11
select e.empno, e.ename, e.emp_kind, k1.office_sal, k2.sal
from emp_kind e, emp_kind1 k1, emp_kind2 k2
where e.empno=k1.empno(+)
and e.empno=k2.empno(+)
order by e.emp_kind;
select e.empno, e.ename, e.emp_kind, k1.office_sal, k2.sal
from emp_kind e left join emp_kind1 k1
on e.empno=k1.empno
left join emp_kind2 k2
on e.empno=k2.empno
order by e.emp_kind;
12
select e.empno, e.ename, e.sal, j.sal as "Jones's Salary"
from emp e, emp j
where upper(j.ename)='JONES'
and j.sal < e.sal;
select e.empno, e.ename, e.sal, j.sal as "Jones's Salary"
from emp e join emp j
on upper(j.ename)='JONES'
and j.sal < e.sal;
13
select d.deptno, d.dname, d.loc, decode(count(e.deptno),0,'NO','YES') as emp
from dept d, emp e
where d.deptno=e.deptno(+)
group by d.deptno, d.dname, d.loc
order by d.deptno
/
select d.deptno, d.dname, d.loc, decode(count(e.deptno),0,'NO','YES') as emp
from dept d left outer join emp e
on d.deptno=e.deptno
group by d.deptno, d.dname, d.loc
order by d.deptno;
14
select e.first_name, e.last_name, e.salary, e.job_id, c.country_name
from employees e,
departments d
, locations l
, countries c
where e.department_id=d.department_id
and d.location_id=l.location_id
and l.country_id=c.country_id
and initcap(c.country_name)='Canada';
select e.first_name, e.last_name, e.salary, e.job_id, c.country_name
from employees e
join departments d
on e.department_id=d.department_id
join locations l
on d.location_id=l.location_id
join countries c
on l.country_id=c.country_id
where initcap(c.country_name)='Canada';
15
select p.prod_id, p.prod_name, sum(s.quantity_sold) as sold_sum
from prods p, sales s
where p.prod_id=s.prod_id(+)
group by p.prod_id, p.prod_name;
select p.prod_id, p.prod_name, sum(s.quantity_sold) as sold_sum
from prods p left outer join sales s
on p.prod_id=s.prod_id
group by p.prod_id, p.prod_name;
--
SELECT *
FROM EMPLOYEES
WHERE DEPARTMENT_ID = (SELECT DEPARTMENT_ID
FROM EMPLOYEES
WHERE EMPLOYEE_ID = 141)
AND EMPLOYEE_ID NOT IN (141) ;
--
--SELECT EMPLOYEE_ID, MIN(SALARY)
--FROM EMPLOYEES
--GROUP BY EMPLOYEE_ID;
SELECT *
FROM EMPLOYEES
WHERE SALARY = (SELECT MIN(SALARY) FROM EMPLOYEES);
--
SELECT DEPARTMENT_ID, MIN(SALARY)
FROM EMPLOYEES
GROUP BY DEPARTMENT_ID
HAVING MIN(SALARY) > (SELECT MIN(SALARY) FROM EMPLOYEES);
-- 100, 999
-- ์๋ธ์ฟผ๋ฆฌ ๋ฆฌํด ๊ฐ์ด NULL์ธ ๊ฒฝ์ฐ-> NVLํจ์ ํ์ฉํ ์์ ํ
select last_name, commission_pct
from employees
where commission_pct = (select commission_pct
from employees
where employee_id=100);
-- ์๋ธ์ฟผ๋ฆฌ ๋ฆฌํด ๊ฐ์ด NULL์ธ ๊ฒฝ์ฐ
select commission_pct
from employees
where employee_id=100;
-- ์๋ธ์ฟผ๋ฆฌ ๋ฆฌํด ๊ฐ์ด NULL์ธ ๊ฒฝ์ฐ-> NVLํจ์ ํ์ฉํ ์์ ํ
select last_name, commission_pct
from employees
where nvl(commission_pct,0) = (select nvl(commission_pct,0)
from employees
where employee_id=100);
--
select last_name, commission_pct
from employees
where nvl(commission_pct,0) = (select nvl(commission_pct,0)
from employees
where employee_id=999);
select nvl(commission_pct,0)
from employees
where employee_id=999;
-- ์๋ธ์ฟผ๋ฆฌ ๋ฐํ ๊ฐ์ด ์ฌ๋ฌ๊ฐ์ธ ๊ฒฝ์ฐ '=' ์๋
-- IN ์ฐ์ฐ์ OR '=ANY' ์ฌ์ฉ ํ
SELECT last_name, salary, department_id
FROM employees
WHERE salary IN (SELECT MIN(salary)
FROM employees
GROUP BY department_id);
-- ALL ์ด๋ค ๊ฐ๊ณผ ๋น๊ตํด๋ ๊ทธ ๊ฐ๋ณด๋ค ์์์ผ ํ๋ค
-- ALL๋ณด๋ค ์์ ๊ฒ์ MIN ๋ณด๋ค ์๋ค
-------------------------------
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary < ANY (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-- OR
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary < MAX (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-----------------------------------
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary > ANY (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-- OR
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary > MIN (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
---------------------------------
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary < ALL (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-- OR
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary < MIN (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
---------------------------------
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary > ALL (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-- OR
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary > MAX (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-----------------------------
<ANY
๋ ์ต๋๊ฐ๋ณด๋ค ์์์ ์๋ฏธํฉ๋๋ค.>ANY
๋ ์ต์๊ฐ๋ณด๋ค ํผ์ ์๋ฏธํฉ๋๋ค.=ANY
๋ IN
๊ณผ ๊ฐ์ต๋๋ค.<ALL
์ ์ต์๊ฐ๋ณด๋ค ์์์ ์๋ฏธํฉ๋๋ค.>ALL
์ ์ต๋๊ฐ๋ณด๋ค ํผ์ ์๋ฏธํฉ๋๋ค.-- ALL ์ด๋ค ๊ฐ๊ณผ ๋น๊ตํด๋ ๊ทธ ๊ฐ๋ณด๋ค ์์์ผ ํ๋ค
-- ALL๋ณด๋ค ์์ ๊ฒ์ MIN ๋ณด๋ค ์๋ค
-------------------------------
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary < ANY (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-- OR
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary < MAX (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-----------------------------------
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary > ANY (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-- OR
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary > MIN (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
---------------------------------
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary < ALL (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-- OR
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary < MIN (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
---------------------------------
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary > ALL (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-- OR
SELECT
FROM
WHERE
employee_id, last_name, job_id, salary
employees
salary > MAX (9000,6000,4200)
(SELECT salary
FROM employees
WHERE job_id = 'IT_PROG')
AND job_id <> 'IT_PROG';
-----------------------------