[SQL문제풀기] 조건에 맞는 도서 리스트 출력하기

silver's avatar
Apr 29, 2025
[SQL문제풀기] 조건에 맞는 도서 리스트 출력하기

문제

MYSQL

내가 작성한 정답1

select book_id, date_format(published_date,'%Y-%m-%d') published_date from book where category = '인문' and date_format(published_date,'%Y') = '2021' order by 2;

내가 작성한 정답2

SELECT book_id, date_format(published_date,'%Y-%m-%d') published_date from book where category = '인문' and published_date between '2021-01-01' and '2021-12-31' order by 2;

ORACLE

내가 작성한 정답1

select book_id, to_char(published_date,'yyyy-mm-dd') published_date from book where category = '인문' and to_char(published_date,'yyyy') = '2021' order by 2;

내가 작성한 정답2

: oracle에서는 date 타입을 변경해주지 않으면 between '2021-01-01' and '2021-12-31' 이런식으로 날짜를 비교할 수 없어 오류가 발생하기 때문에 타입을 변경한 후 between으로 비교해야 한다.
notion image
select book_id, to_char(published_date,'yyyy-mm-dd') published_date from book where category = '인문' and to_char(published_date,'yyyy-mm-dd') between '2021-01-01' and '2021-12-31' order by 2;
Share article

silver