문제/SQL

23.10.11. Class 복습 겸 문제

잇꼬 2023. 10. 11. 17:42
728x90
반응형
SMALL

[문제1] 2005년도에 홀수달에 입사한 사원들의 정보를 출력해주세요.

DESC employees
SELECT * FROM nls_session_parameters;

-- 홀수달 계산
SELECT 
    to_char(hire_date, 'mm') , -- 문자타입(왼쪽)
    mod(to_number(to_char(hire_date, 'mm')),2) , 
    -- 문자타입(to_char)을 숫자타입(to_number)을 변형후에 mod()함수 사용하기
    salary -- 숫자타입(오른쪽)
FROM hr.employees;

 

[방법1] 

BETWEEN - AND 

SELECT *
FROM hr.employees
WHERE hire_date BETWEEN to_date('2005/01/01', 'yyyy/mm/dd') AND to_date('2005/12/31', 'yyyy/mm/dd')
AND mod(to_number(to_char(hire_date, 'mm')),2) = 1;

 

[방법2]

비교연산자

SELECT *
FROM hr.employees
WHERE hire_date >= to_date('2005/01/01', 'yyyy/mm/dd') 
AND hire_date <= to_date('2005/12/31', 'yyyy/mm/dd')
AND mod(to_number(to_char(hire_date, 'mm')),2) = 1;

SELECT * 
FROM hr.employees
WHERE hire_date >= to_date('05/01/01', 'rr/mm/dd')
AND hire_date <= to_date('05/12/31', 'rr/mm/dd');

SELECT * 
FROM hr.employees
WHERE hire_date >= to_date('2005/01/01', 'yyyy/mm/dd')
AND hire_date <= to_date('2005/12/31', 'yyyy/mm/dd');

 

728x90
반응형
LIST