https://school.programmers.co.kr/learn/courses/30/lessons/164672
코드설명
CASE WHEN + DATE_FORMAT 을 사용합니다.
간단하게 풀 수 있습니다.
코드
SELECT BOARD_ID, WRITER_ID, TITLE, PRICE,
CASE
WHEN STATUS = 'SALE' THEN '판매중'
WHEN STATUS = 'DONE' THEN '거래완료'
WHEN STATUS = 'RESERVED' 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 UGB.BOARD_ID, UGB.WRITER_ID, UGB.TITLE, UGB.PRICE,
CASE
WHEN UGB.STATUS = 'SALE' THEN '판매중'
WHEN UGB.STATUS = 'RESERVED' THEN '예약중'
WHEN UGB.STATUS = 'DONE' THEN '거래완료'
END AS 'STATUS'
FROM USED_GOODS_BOARD AS UGB
WHERE UGB.CREATED_DATE = '2022-10-5'
ORDER BY BOARD_ID DESC
ORACLE
SELECT UGB.BOARD_ID, UGB.WRITER_ID, UGB.TITLE, UGB.PRICE,
CASE
WHEN UGB.STATUS = 'SALE' THEN '판매중'
WHEN UGB.STATUS = 'RESERVED' THEN '예약중'
WHEN UGB.STATUS = 'DONE' THEN '거래완료'
END AS STATUS
FROM USED_GOODS_BOARD UGB
WHERE TO_CHAR(UGB.CREATED_DATE, 'YYYY-MM-DD') = '2022-10-05'
ORDER BY UGB.BOARD_ID DESC