๐ซ ๋ฌธ์
๐ซ CODE
SELECT a.TITLE, a.BOARD_ID, b.REPLY_ID, b.WRITER_ID, b.CONTENTS, DATE_FORMAT(b.CREATED_DATE, '%Y-%m-%d') AS CREATED_DATE
FROM USED_GOODS_BOARD a
JOIN USED_GOODS_REPLY b ON a.BOARD_ID = b.BOARD_ID
WHERE YEAR(a.CREATED_DATE) = 2022 AND MONTH(a.CREATED_DATE) = 10
ORDER BY b.CREATED_DATE asc, a.TITLE asc;
ย
๐ซ ํ์ด ์กฐ๊ฑด
1. 2022๋ 10์์ ์์ฑ๋ ๊ฒ์๊ธ
2. ๋๊ธ ์์ฑ์ผ์ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
3. ๋๊ธ ์์ฑ์ผ์ด ๊ฐ๋ค๋ฉด ๊ฒ์๊ธ ์ ๋ชฉ์ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌ
ย
๐ซ ํ์ด
1. SELECT a.TITLE, a.BOARD_ID, b.REPLY_ID, b.WRITER_ID, b.CONTENTS, DATE_FORMAT(b.CREATED_DATE, '%Y-%m-%d') AS CREATED_DATE
- USED_GOODS_BOARD ํ ์ด๋ธ์ ๊ฒ์๊ธ ์ ๋ชฉ (TITLE), ๊ฒ์๊ธ ID (BOARD_ID) ์กฐํ
- USED_GOODS_REPLY ํ ์ด๋ธ์ ๋๊ธ ID (REPLY_ID), ์์ฑ์ ID (WRITER_ID), ๋๊ธ ๋ด์ฉ(CONTENTS), ๋๊ธ ์์ฑ์ผ (CREATED_DATE) ์กฐํ
2. DATE_FORMAT(b.CREATED_DATE, '%Y-%m-%d') AS CREATED_DATE
- DATE_FORMAT ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์์ฑ์ผ์ด ๋ ๋-์-์ผ ๊น์ง๋ง ์ถ๋ ฅ ๋๋๋ก ๋ณ๊ฒฝ
- AS๋ฅผ ์ฌ์ฉํ์ฌ ์ปฌ๋ผ๋ช ์ CREATED_DATE๋ก ๋ณ์นญ ์ฃผ๊ธฐ
3. FROM USED_GOODS_BOARD a
- USED_GOODS_BOARD ํ ์ด๋ธ ๋ณ์นญ์ a๋ก ์ง์
4. JOIN USED_GOODS_REPLY b ON a.BOARD_ID = b.BOARD_ID
- JOIN ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๋ค๋ฅธ ํ ์ด๋ธ(USED_GOODS_REPLY) ์กฐ์ธ
- ์กฐ์ธ ์กฐ๊ฑด : ON a.BOARD_ID = b.BOARD_ID
- USED_GOODS_REPLY ํ ์ด๋ธ ๋ณ์นญ b๋ก ์ง์
5. WHERE YEAR(a.CREATED_DATE) = 2022 AND MONTH(a.CREATED_DATE) = 10
- ์กฐ๊ฑด : ๊ธ ์์ฑ์ผ(a.CREATED_DATE) ์ค ๋ ๋๊ฐ 2022๋ ๋ ์ด๊ณ , ์์ด 10์์ธ ์ปฌ๋ผ
6. ORDER BY b.CREATED_DATE asc, a.TITLE asc;
- ORDER BY๋ฅผ ์ด์ฉํ์ฌ ๋๊ธ ์์ฑ์ผ(b.CREATED_DATE) ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์, ๋๊ธ ์์ฑ์ผ์ด ๊ฐ๋ค๋ฉด ๊ฒ์๊ธ ์ ๋ชฉ(TITLE)์ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌ