CODEKATA

SQL CODEKATA 45번

임빵빵 2024. 7. 3. 09:25

45번 - 3월에 태어난 여성 회원 목록 출력하기

MEMBER_PROFILE 테이블에서 생일이 3월인 여성 회원의 ID, 이름, 성별, 생년월일을 조회하는 SQL문을 작성해주세요. 이때 전화번호가 NULL인 경우는 출력대상에서 제외시켜 주시고, 결과는 회원ID를 기준으로 오름차순 정렬해주세요.

select member_id,
       member_name,
       gender,
       date_format(date_of_birth, '%Y-%m-%d') date_of_birth
from member_profile
where gender='W' and tlno is not null and month(date_of_birth) = '03'
order by 1

 

  1. 조회 : 회원ID, 이름, 성별, 생년원일
  2. date_format 형식을 통해 날짜 형식 바꿔주기
  3. 조건 :  여성 회원 -- where gender = 'W'     생일이 3월 -- month(date_of_birth) = '03'   전화번호가 NULL인 경우 출력대상에서 제외 -- where tlno is not null
  4. 순서: 회원ID를 기준으로 오름차순 정렬이기 때문에 oder by 1