[sql] 조건에 맞는 개발자 찾기

whitehousechef·2025년 12월 1일

https://school.programmers.co.kr/learn/courses/30/lessons/276034

initial

im thinking of joining 2 tables on the code and filter via where if skill code matches python or c#

but the prob is developers skill is a sum of all the skills. So we have to use bitwise AND operator to filter the skills that developer has that matches any skill in the skills list.

select a.id, a.email, a.first_name, a.last_name
from developers a
join SKILLCODES b
on a.skill_code & b.code = b.code
where b.code in (1024, 256)
order by a.id asc

but if a developer has both python and c# skill, there will be duplicate rows in the output. So we need to use DISTINCT KEYWORD, which eliminate rows where all four selected values are exactly the same.

even when i included distinct keyword it still didnt work. Actually hardcoding the values for where condition is wrong cuz for other cases, the skill value for py and c# will not be 1024 or 256. Instead we should have a better way to filter out the skills so for where, use name instead of hard-coded values.

sol

select distinct a.id, a.email, a.first_name, a.last_name
from developers a
join SKILLCODES b
on a.skill_code & b.code = b.code
WHERE b.NAME IN ('Python', 'C#')
order by a.id asc

0개의 댓글