๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Coding Test/SQL

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์กฐ๊ฑด์— ๋งž๋Š” ์‚ฌ์šฉ์ž ์ •๋ณด ์กฐํšŒํ•˜๊ธฐ/MySQL - Lv.3

by The Future Engineer, Lucy 2024. 9. 28.
728x90
๋ฐ˜์‘ํ˜•

โ“๋ฌธ์ œ

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

๐Ÿ“Œ์œ ํ˜•

์ง‘๊ณ„, ๋ฌธ์ž์—ด

โœ๐Ÿปํ’€์ด

 CITY, STREET_ADDRESS1, STREET_ADDRESS2๋ฅผ ๋ชจ๋‘ ์—ฐ๊ฒฐํ•˜์—ฌ ์ „์ฒด์ฃผ์†Œ๋กœ ์ถœ๋ ฅ๋˜๋„๋ก ํ•˜๋ผ๊ณ  ํ•˜์˜€์œผ๋ฏ€๋กœ concat ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์—ฐ๊ฒฐ.
 SUBSTRING์„ ์ด์šฉํ•˜์—ฌ TLNO ๋ฌธ์ž์—ด์„ 3, 4, 4๊ฐœ๋กœ ๋‚˜๋ˆ„์–ด ์ค‘๊ฐ„์— '-'๋ฅผ ๋„ฃ์–ด xxx-xxxx-xxxxํ˜•ํƒœ๋กœ ์ถœ๋ ฅ๋˜๋„๋ก ํ•จ.

๐Ÿ’ป์ฝ”๋“œ

SELECT USER_ID, NICKNAME, CONCAT(CITY, ' ', STREET_ADDRESS1, ' ', STREET_ADDRESS2) AS '์ „์ œ์ฃผ์†Œ', CONCAT(SUBSTRING(TLNO, 1, 3), '-',SUBSTRING(TLNO, 4, 4), '-', SUBSTRING(TLNO, 8, 4)) AS '์ „ํ™”๋ฒˆํ˜ธ'
FROM USED_GOODS_USER
WHERE USER_ID IN (SELECT WRITER_ID
                  FROM USED_GOODS_BOARD
                  GROUP BY WRITER_ID
                  HAVING COUNT(*) >= 3)
ORDER BY USER_ID DESC
728x90
๋ฐ˜์‘ํ˜•