SELECT DEPARTMENT_ID FROM EMPLOYEES e ;
SELECT * FROM DEPARTMENTS d ;
SELECT e.EMPLOYEE_ID , e.DEPARTMENT_ID
, d.DEPARTMENT_ID , d.DEPARTMENT_NAME
FROM EMPLOYEES e
INNER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE e.EMPLOYEE_ID = 178
;
SELECT *
FROM EMPLOYEES e
WHERE DEPARTMENT_ID IS NULL ;
SELECT e.EMPLOYEE_ID , e.FIRST_NAME
, d.DEPARTMENT_ID , d.DEPARTMENT_NAME
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d -- DEPARTMENTS 를 기준으로 가져옴
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
;
SELECT e.EMPLOYEE_ID , e.FIRST_NAME
, d.DEPARTMENT_ID , d.DEPARTMENT_NAME
FROM EMPLOYEES e
RIGHT OUTER JOIN DEPARTMENTS d -- DEPARTMENTS 를 기준으로 가져옴
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
;
SELECT *
FROM JOB_HISTORY jh
ORDER BY EMPLOYEE_ID
;
SELECT e.EMPLOYEE_ID , e.FIRST_NAME, e.HIRE_DATE
, jh.START_DATE , jh.END_DATE , jh.JOB_ID
FROM EMPLOYEES e
LEFT OUTER JOIN JOB_HISTORY jh
ON e.EMPLOYEE_ID = jh.EMPLOYEE_ID
;
SELECT e.FIRST_NAME , d.DEPARTMENT_ID , d.DEPARTMENT_NAME
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
;
SELECT e.FIRST_NAME , e.JOB_ID , d.DEPARTMENT_NAME
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE e.DEPARTMENT_ID = 30
;
SELECT e.FIRST_NAME , e.JOB_ID , e.DEPARTMENT_ID , d.DEPARTMENT_NAME
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE e.COMMISSION_PCT IS NOT NULL
;
SELECT d.LOCATION_ID , e.FIRST_NAME , e.JOB_ID , d.DEPARTMENT_ID , d.DEPARTMENT_NAME
FROM EMPLOYEES e
FULL OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE d.LOCATION_ID = 2500
;
SELECT e.FIRST_NAME , d.DEPARTMENT_NAME
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE e.FIRST_NAME LIKE '%A%'
;
SELECT e.EMPLOYEE_ID, e.FIRST_NAME ,e2.FIRST_NAME
FROM EMPLOYEES e
INNER JOIN EMPLOYEES e2
ON e.EMPLOYEE_ID = e2.MANAGER_ID
;
SELECT e.FIRST_NAME , d.DEPARTMENT_NAME, e.JOB_ID , e.DEPARTMENT_ID , e.SALARY
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE e.SALARY >= 3000
ORDER BY SALARY
;
SELECT e.FIRST_NAME , d.DEPARTMENT_NAME, SALARY
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE e.SALARY BETWEEN 3000 AND 5000
ORDER BY SALARY
;
SELECT e.FIRST_NAME , e.SALARY , d.LOCATION_ID , l.CITY
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
LEFT OUTER JOIN LOCATIONS l
ON d.LOCATION_ID = l.LOCATION_ID
WHERE SALARY <= 3000
;
SELECT d.DEPARTMENT_NAME , e.FIRST_NAME , e.LAST_NAME
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON d.DEPARTMENT_ID = e.DEPARTMENT_ID
WHERE e.FIRST_NAME LIKE 'Steven'
AND e.LAST_NAME LIKE 'King'
;
SELECT e.FIRST_NAME , e.LAST_NAME , d.DEPARTMENT_NAME
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE d.DEPARTMENT_NAME = 'IT'
;
SELECT e.EMPLOYEE_ID , e.FIRST_NAME , e.JOB_ID , e.DEPARTMENT_ID
, d.DEPARTMENT_ID , d.DEPARTMENT_NAME, d.LOCATION_ID
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
;
SELECT e.EMPLOYEE_ID , e.FIRST_NAME , e.SALARY , d.DEPARTMENT_ID , d.LOCATION_ID, d.DEPARTMENT_NAME
FROM EMPLOYEES e
LEFT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
WHERE JOB_ID = 'SA_MAN'
;
SELECT EMPLOYEE_ID, FIRST_NAME, JOB_ID , d.DEPARTMENT_ID , d.DEPARTMENT_NAME
, d.LOCATION_ID , e.DEPARTMENT_ID
FROM EMPLOYEES e
RIGHT OUTER JOIN DEPARTMENTS d
ON e.DEPARTMENT_ID = d.DEPARTMENT_ID
;
--6462
SELECT ROUND(AVG(SALARY))
FROM EMPLOYEES e
;
SELECT *
FROM EMPLOYEES e
WHERE SALARY <6462
;
SELECT *
FROM EMPLOYEES e
WHERE SALARY < (SELECT ROUND(AVG(SALARY))
FROM EMPLOYEES e)
;
SELECT *
FROM LOCATIONS l
WHERE COUNTRY_ID = 'US'
;
SELECT LOCATION_ID
FROM DEPARTMENTS d
WHERE LOCATION_ID IN (1400, 1500, 1600, 1700)
;
SELECT *
FROM DEPARTMENTS d
WHERE LOCATION_ID IN (SELECT LOCATION_ID
FROM LOCATIONS l
WHERE COUNTRY_ID = 'US')
;
SELECT MIN(SALARY)
FROM EMPLOYEES e
;
SELECT FIRST_NAME , SALARY
FROM EMPLOYEES e
WHERE e.SALARY IN (SELECT MIN(SALARY)
FROM EMPLOYEES e)
;
SELECT MAX(SALARY)
FROM EMPLOYEES e
;
SELECT FIRST_NAME , SALARY
FROM EMPLOYEES e
WHERE SALARY IN (SELECT MAX(SALARY)
FROM EMPLOYEES e)
;
SELECT SALARY
FROM EMPLOYEES e
;
SELECT EMPLOYEE_ID ,FIRST_NAME , LAST_NAME , JOB_ID , SALARY
FROM EMPLOYEES e
WHERE e.SALARY > (SELECT SALARY
FROM EMPLOYEES e
WHERE LAST_NAME = 'Kochhar')
;
SELECT ROUND(AVG(SALARY))
FROM EMPLOYEES e
;
SELECT *
FROM EMPLOYEES e
WHERE SALARY < (SELECT AVG(SALARY)
FROM EMPLOYEES e)
ORDER BY SALARY
;
SELECT MIN(SALARY)
FROM EMPLOYEES e
WHERE DEPARTMENT_ID = 100
;
SELECT DEPARTMENT_ID , MIN(SALARY)
FROM EMPLOYEES e
GROUP BY DEPARTMENT_ID
HAVING MIN(SALARY) > ( SELECT MIN(SALARY)
FROM EMPLOYEES e
WHERE DEPARTMENT_ID = 100)
;
단 업무별로 정렬하여라.
--업무별 급여의 최소값.
SELECT JOB_ID , MIN(SALARY)
FROM EMPLOYEES e
GROUP BY JOB_ID
;
SELECT e.EMPLOYEE_ID , e.FIRST_NAME , e.JOB_ID , e.SALARY , e.DEPARTMENT_ID
FROM EMPLOYEES e
WHERE (JOB_ID, SALARY) IN (SELECT JOB_ID , MIN(SALARY)
FROM EMPLOYEES e
GROUP BY JOB_ID)
ORDER BY JOB_ID
;
SELECT JOB_ID FROM EMPLOYEES e WHERE EMPLOYEE_ID = 123;
SELECT SALARY FROM EMPLOYEES e WHERE EMPLOYEE_ID = 192;
SELECT EMPLOYEE_ID , FIRST_NAME , JOB_ID , SALARY
FROM EMPLOYEES e
WHERE JOB_ID = (SELECT JOB_ID FROM EMPLOYEES e WHERE EMPLOYEE_ID = 123)
AND SALARY > (SELECT SALARY FROM EMPLOYEES e WHERE EMPLOYEE_ID = 192)
;
-- 단 50번은 제외
SELECT MIN(SALARY) FROM EMPLOYEES e WHERE DEPARTMENT_ID = 50;
SELECT *
FROM EMPLOYEES e
WHERE SALARY > (SELECT MIN(SALARY) FROM EMPLOYEES e WHERE DEPARTMENT_ID = 50)
AND DEPARTMENT_ID <> 50
;
/*SELECT e.EMPLOYEE_ID , e.FIRST_NAME , e.JOB_ID , jh.START_DATE , e.SALARY , e.DEPARTMENT_ID
FROM EMPLOYEES e
LEFT OUTER JOIN JOB_HISTORY jh
ON e.EMPLOYEE_ID = jh.EMPLOYEE_ID
WHERE SALARY > (SELECT MIN(SALARY) FROM EMPLOYEES e WHERE DEPARTMENT_ID = 50)
ORDER BY SALARY
;
*/