๐Ÿ’ SQL (Programmers)/Select

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค][MySQL] ์กฐ๊ฑด์— ๋งž๋Š” ๊ฐœ๋ฐœ์ž ์ฐพ๊ธฐ (level2)

์„ ๋‹ฌ 2024. 11. 21. 17:56
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

DEVELOPERS ํ…Œ์ด๋ธ”์—์„œ Python์ด๋‚˜ C# ์Šคํ‚ฌ์„ ๊ฐ€์ง„ ๊ฐœ๋ฐœ์ž์˜ ์ •๋ณด๋ฅผ ์กฐํšŒํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ์กฐ๊ฑด์— ๋งž๋Š” ๊ฐœ๋ฐœ์ž์˜ ID, ์ด๋ฉ”์ผ, ์ด๋ฆ„, ์„ฑ์„ ์กฐํšŒํ•˜๋Š” SQL ๋ฌธ์„ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”.

๊ฒฐ๊ณผ๋Š” ID๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ•ด ์ฃผ์„ธ์š”.

 

ํ’€์ด

๊ฐœ๋ฐœ์ž ์ •๋ณด์™€ ์Šคํ‚ฌ ์ •๋ณด๋ฅผ joinํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”

DEVELOPER ํ…Œ์ด๋ธ”์˜ SKILL_CODE์™€ SKILLCODES ํ…Œ์ด๋ธ”์˜ CODE๋ฅผ ์—ฎ์–ด์•ผํ•œ๋‹ค

์Šคํ‚ฌ์ฝ”๋“œ์™€ ์ฝ”๋“œ๊ฐ€ ๋‘˜ ๋‹ค ์ด์ง„์ˆ˜๊ธฐ ๋•Œ๋ฌธ์— ๋น„ํŠธ์—ฐ์‚ฐ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

 

from DEVELOPERS d left join SKILLCODES s on (d.SKILL_CODE & s.CODE) = s.CODE

 

์˜ˆ๋ฅผ ๋“ค์–ด ์Šคํ‚ฌ์ฝ”๋“œ๊ฐ€ ์ด์ง„์ˆ˜๋กœ 1001(2) ์ด๋ผ๊ณ ํ•˜์ž,

1001 & 1000 = 1000

1001 & 0100 = 0000

1001 & 0010 = 0000

1001 & 0001 = 0001

์ด๋‹ค.

 

๋”ฐ๋ผ์„œ ์Šคํ‚ฌ์ฝ”๋“œ์™€ ์ฝ”๋“œ์˜ & ์—ฐ์‚ฐ ๊ฒฐ๊ณผ๊ฐ€ ์ฝ”๋“œ์™€ ๊ฐ™๋‹ค๋ฉด,

ํ•ด๋‹น ์ฝ”๋“œ๊ฐ€ ์Šคํ‚ฌ์ฝ”๋“œ์— ํฌํ•จ๋˜์–ด์žˆ๋Š” ๊ฒƒ๊ณผ ๊ฐ™๊ณ 

ํ•ด๋‹น ๊ฐœ๋ฐœ์ž๊ฐ€ ํ•ด๋‹น ์Šคํ‚ฌ์„ ๋ณด์œ ํ•œ ๊ฒƒ๊ณผ ๊ฐ™๋‹ค.

 

select distinct d.ID, d.EMAIL, d.FIRST_NAME, d.LAST_NAME
from DEVELOPERS d left join SKILLCODES s on (d.SKILL_CODE & s.CODE) = s.CODE
where s.NAME in ('Python', 'C#')
order by d.ID

 

๋ฐ˜์‘ํ˜•