์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- ๋ฆฌํธ์ฝ๋
- 2์ฃผ ํ๋ก์ ํธ
- ์์ ์ตํ๋ฉฐ ๋ฐฐ์ฐ๋ ๋คํธ์ํฌ ์ฒซ๊ฑธ์
- ์ฝ์ด ์๋ฐ์คํฌ๋ฆฝํธ
- ํ์ ์คํฌ๋ฆฝํธ ์ฌ์ธ์
- ์ ๋ก์ด
- SQL ๊ณ ๋์ Kit
- ํ์ ์คํฌ๋ฆฝํธ
- javascript
- ์๋ฐ์คํฌ๋ฆฝํธ
- ๋ ์ธ ๊ธฐ๋ฆฟ ์๋ฐ์คํฌ๋ฆฝํธ
- ํ์ด์ฌ
- ๋ฐฑ์ค
- ํ๊ณ
- 4์ฃผ ํ๋ก์ ํธ
- ์๊ณ ๋ฆฌ์ฆ
- LeetCode
- js
- ๋ฆฌ๋์ค
- ์ฝ๋์คํ ์ด์ธ
- ํ ์ต
- ์ ์ฌ๋จ
- ํ๋ก๊ทธ๋๋จธ์ค
- ๋ฆฌ์กํธ
- til
- codestates
- ํ์์ดํ
- programmers
- python
- Async
- Today
- Total
Jerry
[ํ๋ก๊ทธ๋๋จธ์ค/SQL ๊ณ ๋์ Kit] ์กฐ๊ฑด์ ๋ถํฉํ๋ ์ค๊ณ ๊ฑฐ๋ ๋๊ธ ์กฐํํ๊ธฐ ๋ณธ๋ฌธ
[ํ๋ก๊ทธ๋๋จธ์ค/SQL ๊ณ ๋์ Kit] ์กฐ๊ฑด์ ๋ถํฉํ๋ ์ค๊ณ ๊ฑฐ๋ ๋๊ธ ์กฐํํ๊ธฐ
juicyjerry 2023. 11. 6. 10:58๐ช๋ฌธ์
USED_GOODS_BOARD์ USED_GOODS_REPLY ํ
์ด๋ธ์์ 2022๋
10์์ ์์ฑ๋ ๊ฒ์๊ธ ์ ๋ชฉ, ๊ฒ์๊ธ ID, ๋๊ธ ID, ๋๊ธ ์์ฑ์ ID, ๋๊ธ ๋ด์ฉ, ๋๊ธ ์์ฑ์ผ์ ์กฐํํ๋ SQL๋ฌธ์ ์์ฑํด์ฃผ์ธ์. ๊ฒฐ๊ณผ๋ ๋๊ธ ์์ฑ์ผ์ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌํด์ฃผ์๊ณ , ๋๊ธ ์์ฑ์ผ์ด ๊ฐ๋ค๋ฉด ๊ฒ์๊ธ ์ ๋ชฉ์ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌํด์ฃผ์ธ์.
๐ช ๋์ ์ ๋ต
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 AS a
INNER JOIN USED_GOODS_REPLY AS b
# ON a.WRITER_ID = b.WRITER_ID
ON a.BOARD_ID = b.BOARD_ID
WHERE DATE_FORMAT(a.CREATED_DATE, '%Y-%m') = '2022-10'
ORDER BY b.CREATED_DATE ASC, a.TITLE;
๐ช ๋ค๋ฅธ ์ ๋ต
<LIKE ํ์ฉ>
SELECT B.TITLE, B.BOARD_ID, R.REPLY_ID, R.WRITER_ID, R.CONTENTS,
DATE_FORMAT(R.CREATED_DATE,"%Y-%m-%d") AS CREATED_DATE
FROM USED_GOODS_BOARD AS B
INNER JOIN USED_GOODS_REPLY AS R
ON B.BOARD_ID = R.BOARD_ID
-- WHERE MONTH(B.CREATED_DATE) = 10
WHERE B.CREATED_DATE like '2022-10%'
ORDER BY R.CREATED_DATE ASC, B.TITLE ASC;
<SUBSTR ํ์ฉ>
SELECT B.TITLE, B.BOARD_ID, R.REPLY_ID, R.WRITER_ID, R.CONTENTS,
DATE_FORMAT(R.CREATED_DATE,"%Y-%m-%d") AS CREATED_DATE
FROM USED_GOODS_BOARD AS B
INNER JOIN USED_GOODS_REPLY AS R
ON B.BOARD_ID = R.BOARD_ID
-- WHERE MONTH(B.CREATED_DATE) = 10
-- WHERE B.CREATED_DATE like '2022-10%'
-- WHERE DATE_FORMAT(B.CREATED_DATE, '%Y-%m') = '2022-10'
WHERE SUBSTR(B.CREATED_DATE,1,7) = '2022-10'
ORDER BY R.CREATED_DATE ASC, B.TITLE ASC;
<BETWEEN ํ์ฉ>
SELECT B.TITLE, B.BOARD_ID, R.REPLY_ID, R.WRITER_ID, R.CONTENTS,
DATE_FORMAT(R.CREATED_DATE,"%Y-%m-%d") AS CREATED_DATE
FROM USED_GOODS_BOARD AS B
INNER JOIN USED_GOODS_REPLY AS R
ON B.BOARD_ID = R.BOARD_ID
-- WHERE MONTH(B.CREATED_DATE) = 10
-- WHERE B.CREATED_DATE like '2022-10%'
-- WHERE DATE_FORMAT(B.CREATED_DATE, '%Y-%m') = '2022-10'
-- WHERE SUBSTR(B.CREATED_DATE,1,7) = '2022-10'
WHERE B.CREATED_DATE BETWEEN ('2022-10-01') AND ('2022-10-31')
ORDER BY R.CREATED_DATE ASC, B.TITLE ASC;
๐ช ๋ฐฐ์ด ์
- ๋ฌธ์ ๋ฅผ ๊ผผ๊ผผํ ์ฝ์ด์ผ ํจ์ ๋๊ผ๋ค.
- LIKE๋ฌธ์ ํ์ฉ, SUBSTR์ ํ์ฉ, BETWEEN์ ํ์ฉ๊ณผ ๊ฐ์ ๋ค์ํ ๊ตฌ๋ฌธ์ ํ์ฉ๋ฒ์ ๋ฐฐ์ ๋ค.
๐ช ๋ง์น๋ฉด์
๋ค์์๋ ๋ค๋ฅธ ๋ฌธ์ ๋ก ์ฐพ์๋ต๊ฒ ์ต๋๋ค!
์๋ :))