Programing/Datababse
[MySQL] 문제풀이 : LOL을 하다가 홧병이 나서 병원을 찾아왔습니다.
블스뜸
2025. 3. 24. 16:10
이제, 아래와 같은 doctors(의사) 테이블이 있습니다.
|
id
|
name
|
major
|
hire_date
|
|
1
|
르탄이
|
피부과
|
2018-05-10
|
|
2
|
배캠이
|
성형외과
|
2019-06-15
|
|
3
|
구구이
|
안과
|
2020-07-20
|
30.
doctors 테이블에서 전공(major)가 성형외과인 의사의 이름을 알아내는 쿼리를 작성해주세요!
더보기
select
name
from doctors
where major = '성형외과'
31.
doctors 테이블에서 각 전공 별 의사 수를 계산하는 쿼리를 작성해주세요!
더보기
select
major,
sum(count(id)) over (partition by major order by count(id)) as cum_major
from doctors
group by 1
32.
doctors 테이블에서 현재 날짜 기준으로 5년 이상 근무(hire_date)한 의사 수를 계산하는 쿼리를 작성해주세요!
더보기
select
count(
case
when b.period = 5 then b.period
end
) as "5년이상 근무 인원"
from(
select
if(TIMESTAMPDIFF(YEAR,a.start_date, a.end_date) >= 5 , 5, 0) as period
from(
select
hire_date as start_date,
DATE_FORMAT(now(), '%Y-%m-%d') as end_date
from doctors
) a
) b
33.
doctors 테이블에서 각 의사의 근무 기간을 계산하는 쿼리를 작성해주세요!
더보기
select
name,
DATEDIFF(now(), hire_date) as "근무기간"
from doctors