[SQL문제풀기] 조건에 맞는 개발자 찾기(JOIN)

241219
이나겸's avatar
Dec 19, 2024
[SQL문제풀기] 조건에 맞는 개발자 찾기(JOIN)
Contents
Q.풀이

Q.

notion image
 

풀이

  • distinct(id)
    • 중복을 제거한 고유한 id
  • join skillcodes on developers.skill_code & skillcodes.code
    • developers 테이블의 skill_code와 skillcode 테이블의 code를 비트 연산자로 비교하여 join
    • skill_code와 code가 공통으로 가진 비트가 있을 때만 매칭
💡

비트 연산자& (비트 AND 연산)

두 숫자를 비트로 변환한 뒤 AND 연산 수행
두 숫자의 각 비트를 비교하여 모두 1인 경우에만 1 반환하는 연산자
  • ex) 숫자 1과 3의 비트 연산
    • 1의 이진수 표현 : 0001
    • 3의 이진수 표현 : 0011
    • 비트 AND 결과 : 0001 (10진수로 1)
      • 0001 (1) & 0011 (3) ⇒ 0001 (결과 : 1)
select distinct(id), email, first_name, last_name from developers join skillcodes on developers.skill_code & skillcodes.code where name = 'C#' or name = 'Python' order by id asc;
Share article

Nakyeom's Study