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

minjjai·2022년 12월 19일
0

문제

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

정답

select MEMBER_ID, MEMBER_NAME, GENDER, date_format(DATE_OF_BIRTH, '%Y-%m-%d') as DATE_OF_BIRTH
from member_profile
where date_format(date_of_birth, '%m') = 03 and gender = 'W' and tlno is not null
order by member_id;

배운 것

  • date_format(x, y)
    datetime타입의 값 x를 문자열y의 형식으로 포맷하여 반환한다.
    ex)
    x -> 2022-12-19 12:12:12
    date_format(x, '%Y-%m-%d') -> '2022-12-19'
    date_format(x, '%m') -> '12'
  • is null & is not null
    ex)
    where x is null and y is not null
    위의 where문을 분석하면 'x컬럼의 값은 null이면서 동시에 y컬럼의 값은 null이 아닌'의 의미가 된다.
profile
BackEnd Developer

0개의 댓글