SQL/GROUP BY
[프로그래머스 ORACLE SQL]자동차 대여 기록에서 대여중 / 대여 가능 여부 구분하기★CASE WHEN THEN
goAhEAd_29
2023. 6. 22. 15:07
728x90
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/157340
SELECT CAR_ID , CASE WHEN AVAILABILITY = 1 THEN '대여중' ELSE '대여 가능' END AS AVAILABILTY FROM (
SELECT CAR_ID , SUM(YN) AS AVAILABILITY FROM (
SELECT CAR_ID , START_DATE, END_DATE, CASE WHEN TO_DATE('20221016' , 'YYYY-MM-DD') BETWEEN START_DATE AND END_DATE THEN 1 ELSE 0 END AS YN FROM CAR_RENTAL_COMPANY_RENTAL_HISTORY)
GROUP BY CAR_ID)
ORDER BY CAR_ID DESC
==> CASE WHEN 조건 THEN ' ' ELSE ' ' END AS
728x90
반응형