https://school.programmers.co.kr/learn/courses/30/lessons/151138
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
select
history_id,
car_id,
date_format(start_date, '%Y-%m-%d') as start_date,
date_format(end_date, '%Y-%m-%d') as end_date,
case
when datediff(end_date, start_date) + 1 >= 30 then '장기 대여'
else '단기 대여'
end as rent_type
from car_rental_company_rental_history
where start_date between '2022-09-01' and '2022-09-30'
order by history_id desc
기간의 일수를 구해야할 때
두 날짜를 빼는 메서드
DATEDIFF(끝, 시작)

'데이터베이스 > 문제 풀이' 카테고리의 다른 글
| [프로그래머스][MySQL] 한 해에 잡은 물고기 수 구하기 (0) | 2026.05.04 |
|---|---|
| [프로그래머스][MySQL] 잡은 물고기의 평균 길이 구하기 (0) | 2026.05.04 |
| [프로그래머스][MySQL] 모든 레코드 조회하기 (0) | 2026.05.04 |
| [프로그래머스][MySQL] Python 개발자 찾기 (0) | 2026.05.04 |
| [프로그래머스][MySQL] 특정 옵션이 포함된 자동차 리스트 구하기 (0) | 2026.04.30 |