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

241231
이나겸's avatar
Dec 31, 2024
[SQL문제풀기] 조건에 맞는 도서 리스트 출력하기(SELECT)

Q.

notion image
 
 

풀이 1

💡

Like

문자열 검색을 위한 조건문
%(와일드 카드)와 함께 사용
  • date_format(published_date, '%Y-%m-%d')
    • published_date를 년-월-일 형식으로 포맷
  • published_date like '2021%'
    • published_date 컬럼값 중 2021로 시작하는 모든 데이터
select book_id, date_format(published_date, '%Y-%m-%d') as published_date from book where category = '인문' and published_date like '2021%' order by published_date asc;

풀이 2

  • published_date >= '2021-01-01' and published_date <= '2021-12-31'
    • 날짜를 나타내는 컬럼값도 대소 비교 가능
    • 2021-01-01 ~ 2021-12-31
select book_id, date_format(published_date, '%Y-%m-%d') as published_date from book where category = '인문' and published_date >= '2021-01-01' and published_date <= '2021-12-31' order by published_date asc;
Share article

Nakyeom's Study