SQL 알고리즘 코드카타

SQL 알고리즘 코드카타 14일차(2) 26.01.12(월)

nom_de_plume 2026. 1. 12. 09:14

부제:

조건에 맞는 도서 리스트 출력하기, 레벨 3

 

1. 문제 링크:https://school.programmers.co.kr/learn/courses/30/lessons/144853
2. 정답 코드: 

SELECT
    book_id,
    date_format(published_date, '%Y-%m-%d') as published_date
from book
where published_date like '2021%' and category='인문'
order by published_date asc


3. 오류 상황:

SELECT
    book_id,
    published_date
from book
where published_date like '2021%' and category like '%인문%'
order by published_date asc

=> 날짜 출력 방법 다름
4. 시도 방법: date_format() 활용
5. 최종 문제 해결 방법:

=> SELECT문에서 출판일을 출력할 때 '년도-월-일' 형식으로 출력해야 하기 때문에 DATE_FORMAT을 활용

=> WHERE문에서 CATEGORY컬럼에는 두 글자가 다이기에 LIKE에서 =으로 바꿔 입