[Programmers_SQL] 2. 3월에 태어난 여성 회원 목록 출력하기

문정준's avatar
Feb 05, 2025
[Programmers_SQL] 2. 3월에 태어난 여성 회원 목록 출력하기
💡
프로그래머스 SELECT 2. 3월에 태어난 여성 회원 목록 출력하기

1. 문제 설명

notion image
 

2. 문제

notion image
 

3. 예시

notion image
notion image

4. 문제 풀이

SELECT member_id, member_name, gender, DATE_FORMAT(date_of_birth,'%Y-%m-%d') as date_of_birth from MEMBER_PROFILE where TLNO is not null and gender = 'W' and month(date_of_birth) = 3 order by member_id asc;
  • 1 Line : 회원ID, 이름, 성별, 생년월일을 조회해야 하므로 select member_id, member_name, gender, date_of_birth
    • 이때, date_of_birth를 바로 참조하면 시, 분, 초까지 나타나는 문제 발생
    • DATE_FORMAT을 사용하여 ‘년도-월-일’의 양식으로 만들어주어야 함
      • DATE_FORMAT(date_of_birth, ‘%Y-%m-%d’) as date_of_birth
  • 2 Line : MEMBER_PROFILE 테이블에서 참조하므로 from MEMBER_PROFILE
  • 3 Line : 여러 조건을 and로 연결 ( 동시 만족해야 하므로 )
    • 전화번호가 NULL이 아니어야 하므로 TLNO is not null
    • 여성 회원을 찾아야 하므로 gender = ‘W’
    • 생일이 3월인 회원을 찾아야 하므로 month(date_of_birth) = 3
  • 4 Line : 회원ID를 기준으로 오름차순 정렬해야 하므로 order by member_id asc;
 

5. 결과 확인

notion image
notion image
 
💡
DATE_FORMAT
Date 속성의 레코드를 특정 양식으로 변환하기 위해 사용하는 SQL 함수
%Y-%m-%d : 0000-00-00
 
Solution 참고 :
Share article

sxias