๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Back-end/DB

[MySQL] ์ปฌ๋Ÿผ ๊ฐ’์„ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ํ•ฉ์น˜๊ธฐ

728x90
๋ฐ˜์‘ํ˜•

๐ŸŸก ์ปฌ๋Ÿผ ๊ฐ’์„ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ํ•ฉ์ณ์„œ ์ถœ๋ ฅํ•˜๋Š” ๋ฐฉ๋ฒ•

 

-> CONCAT ํ•จ์ˆ˜๋ฅผ ํ™œ์šฉํ•˜๋ฉด ๋œ๋‹ค!!!

 

๐Ÿ–ค CONCAT ํ•จ์ˆ˜๋ž€?

๋‘˜ ์ด์ƒ์˜ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•œ ์ˆœ์„œ๋Œ€๋กœ ํ•ฉ์ณ์„œ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜

์—ฌ๋Ÿฌ ๋ฌธ์ž์—ด ํ˜น์€ ์ปฌ๋Ÿผ ๊ฐ’์„ ํ•ฉ์ณ์„œ ๊ฐ€์ ธ์™€์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ์— ์ž์ฃผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค. 

 

 

๐Ÿ–ค ์‹ค์ „ ์˜ˆ์ œ ํ’€์–ด๋ณด๊ธฐ

https://ye5ni.tistory.com/145
↑↑↑(์œ„ ๋งํฌ ์ฐธ๊ณ ) ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ƒ์„ฑ ํ›„ ํ•ด๋‹นํ•˜๋Š” ํ…Œ์ด๋ธ”์„ ๊ธฐ์ค€์œผ๋กœ ์‹ค์Šต ์ง„ํ–‰

 

โœ… ์กฐ๊ฑด 1. ์‹œ๋„๋ช…(sido)์€ '์„œ์šธํŠน๋ณ„์‹œ', ์‹œ๊ตฐ๊ตฌ๋ช…(gugun)์€ '์ค‘๊ตฌ', ๋™๋ช…(dong)์€ 'ํ•„๋™'์œผ๋กœ ์‹œ์ž‘

โœ… ์กฐ๊ฑด 2. ๊ฒฐ๊ณผ๋Š” ์‹œ๋„๋ช…, ์‹œ๊ตฐ๊ตฌ๋ช…, ์๋ฉด๋™๋ช…, ๋„๋กœ๋ช…์˜ ์ˆœ์œผ๋กœ ์ •๋ ฌ

 

โœ… ์˜ˆ์‹œ 

์ด๋Ÿฐ ํ˜•์‹์œผ๋กœ ์ถœ๋ ฅ๋  ์ˆ˜ ์žˆ๋Š” ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•ด๋ณด์ž!

 

 

์—ฌ๊ธฐ์„œ juso ๋ผ๊ณ  ์จ์ ธ ์žˆ๋Š” ๋ถ€๋ถ„๋งŒ ํ•ฉ์น˜๋Š” ๋ฐฉ๋ฒ•์„ ์ž‘์„ฑํ•ด๋ณผ ๊ฒƒ์ด๋‹ค.

์‹ค์ œ๋กœ juso ์ปฌ๋Ÿผ์€ sido, gugun, dong, road ์ปฌ๋Ÿผ์„ ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ํ•ฉ์ณ์„œ ์ƒˆ๋กœ์šด juso ์ปฌ๋Ÿผ์ด ์ƒ์„ฑ๋œ ๊ฒƒ์ด๋‹ค!

 

 

์‚ฌ์šฉ๋ฒ•
CONCAT(๋ฌธ์ž์—ด1, ๋ฌธ์ž์—ด2 [, ๋ฌธ์ž์—ด3 ...])โ€‹

 

 

์˜ˆ์‹œ
select concat(sido, " ", gugun, " ", dong, " ", road) as juso
from road_code;

sido, gugun, dong, road ์ปฌ๋Ÿผ์„ ์ƒˆ๋กœ์šด juso ์ปฌ๋Ÿผ ์•ˆ์— ํ•˜๋‚˜์˜ ๋ฌธ์ž์—ด๋กœ ํ•ฉ์ณ์„œ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•œ ์ฟผ๋ฆฌ์ด๋‹ค. ์ค‘๊ฐ„ ์ค‘๊ฐ„ ๊ฐ ์ปฌ๋Ÿผ ์‚ฌ์ด์— ๊ณต๋ฐฑ์„ ์ฃผ๊ธฐ ์œ„ํ•ด์„œ๋Š” " " ์™€ ๊ฐ™์ด ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ ๋‹ค๋ฅธ ๋ฌธ์ž๋ฅผ ์‚ฝ์ž…ํ•˜์—ฌ ๊ตฌ๋ถ„ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๊ณต๋ฐฑ ์ž๋ฆฌ์— "," or ":" ์™€ ๊ฐ™์ด ์“ธ ์ˆ˜ ์žˆ๋‹ค.

 

 

์˜ˆ์ œ ๋ฌธ์ œ์— ์ ์šฉํ•˜๊ธฐ
select scd, rno, dno, concat(sido, " ", gugun, " ", dong, " ", road) as juso,
concat(eroad, ",", edong, ",", egugun, ",", esido) as ejuso 
from road_code  
where sido="์„œ์šธํŠน๋ณ„์‹œ" and gugun="์ค‘๊ตฌ" and dong like "ํ•„๋™%" 
order by sido, gugun, dong, road;

 

 

 

 

 

order by ์ •๋ ฌ์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…์€ โžก๏ธโžก๏ธโžก๏ธ https://ye5ni.tistory.com/149

like ํ•จ์ˆ˜์— ๋Œ€ํ•œ ์ž์„ธํ•œ ์„ค๋ช…์€ โžก๏ธโžก๏ธโžก๏ธ https://ye5ni.tistory.com/148

728x90
๋ฐ˜์‘ํ˜•