SQL

[SQL 과제 LV. 1] 데이터 속 김서방 찾기

thebuck104 2024. 6. 10. 18:58

 

[SQL 과제 LV. 1] 데이터 속 김서방 찾기

 

#상황: “김”씨로 시작하는 이용자들 수를 세어 보자

 

Table Name > user

  • user_id: 익명화된 유저들의 아이디(varchar255)
  • created_at: 아이디 생성 날짜(timestamp)
  • updated_at: 정보 업데이트 날짜(timestamp)
  • name: 익명화된 유저들의 이름(varchar255)
  • email: 이메일(varchar255)

 

# 문제:

1. name_cnt: “김”씨 성을 가지고 있는 교육생의 수를 구하여라

 

 

# 정답:

select count(distinct(user_id)) as name_cnt
from user
where substring(name, 1, 1) = "김";

select count(distinct(user_id)) as name_cnt
from user
where name like "김%";