Table - patients
id
|
name
|
birth_date
|
gender
|
last_visit_date
|
1
|
르탄이
|
1985-04-12
|
남자
|
2023-03-15
|
2
|
배캠이
|
1990-08-05
|
여자
|
2023-03-20
|
3
|
구구이
|
1982-12-02
|
여자
|
2023-02-18
|
4
|
이션이
|
1999-03-02
|
남자
|
2023-03-17
|
더보기
34.patients 테이블에서 각 성별(gender)에 따른 환자 수를 계산하는 쿼리를 작성해주세요!
select gender,
count(*)
from patients
group by gender
35.patients 테이블에서 현재 나이가 40세 이상인 환자들의 수를 계산하는 쿼리를 작성해주세요!
select count(*) as cnt_patients_40over
from(
select *,
date_format(now(), '%Y') - date_format(birth_date, '%Y') as age
from patients
)a
where a.age>=40
36.patients 테이블에서 마지막 방문 날짜(last_visit_date)가 1년 이상 된 환자들을 선택하는 쿼리를 작성해주세요!
select *
from (
select *,
date(now()) as currentdate,
datediff(date(now()),last_visit_date) as over_days
from patients
)a
where a.over_days >= 365
37.patients 테이블에서 생년월일이 1980년대인 환자들의 수를 계산하는 쿼리를 작성해주세요!
select count(*) as patients_1980
from patients
where date_format(birth_date, '%Y') between 1980 and 1989
'Sparta > SQL-Practice' 카테고리의 다른 글
[MySQL][Practice] 마지막 연습 문제 ! (0) | 2025.04.10 |
---|---|
[MySQL][Practice] 이젠 테이블이 2개입니다 (0) | 2025.04.09 |
[MySQL][Practice] LOL을 하다가 홧병이 나서 병원을 찾아왔습니다. (0) | 2025.04.05 |
[MySQL][Practice] 랭크게임 하다가 싸워서 피드백 남겼어요… (0) | 2025.04.05 |
[MySQL][Practice] 팀 프로젝트 열심히 했으니 다시 놀아볼까요?! (0) | 2025.04.04 |