#42. STRING, DATE : 조건에 부합하는 중고거래 상태 조회하기 | 프로그래머스 | SQL 고득점 Kit

문제

 

입력 코드

1. CASE

SELECT 
    BOARD_ID, WRITER_ID, TITLE, PRICE, 
    (CASE
        WHEN STATUS ='SALE' THEN '판매중'
        WHEN STATUS ='RESERVED' THEN '예약중'
        WHEN STATUS ='DONE' THEN '거래완료'
     END) AS STATUS
FROM USED_GOODS_BOARD
WHERE CREATED_DATE = '2022-10-05'
ORDER BY BOARD_ID DESC;

 

2. CASE - ELSE

SELECT BOARD_ID, WRITER_ID, TITLE, PRICE, 
    (CASE STATUS
        WHEN 'SALE' THEN '판매중'
        WHEN 'RESERVED' THEN '예약중'
        ELSE '거래완료'
    END) AS STATUS
FROM USED_GOODS_BOARD
WHERE DATE_FORMAT(CREATED_DATE, "%Y-%m-%d") = "2022-10-05" 
ORDER BY BOARD_ID DESC;

 

3. DATE_FORMAT

SELECT BOARD_ID, WRITER_ID, TITLE, PRICE, 
    (CASE STATUS
        WHEN 'SALE' THEN '판매중'
        WHEN 'RESERVED' THEN '예약중'
        WHEN 'DONE' THEN '거래완료'
    END) AS STATUS
FROM USED_GOODS_BOARD
WHERE DATE_FORMAT(CREATED_DATE, "%Y-%m-%d") = "2022-10-05" 
ORDER BY BOARD_ID DESC;

 

 

코드 설명

#SELECT #CASE #END #ELSE #WHEN #WHERE #DATE_FORMAT #ORDER BY

 

 

문제 출처

https://school.programmers.co.kr/learn/courses/30/lessons/164672