
30번
Select name
From doctors
Where major=”성형외과”
31번
Select major,
Count(1)
From doctor
Group by major
32번
Select count(*) number_of_doctor
From doctors
Where hire_date<=date_sub(curedate(), interval 5 year)
코드를 잘 몰라서 구글링을 통해 공부했다.
Select count(*)
From doctor
Where year(hire_date)<=year(curedate)-5
33번
Select name,
Datediff(curedate(), hire_date) working_days
From doctors

34번
Select gender,
Count(1)
From patients
Group by gender
35번
Select count(*)
From patients
Where birth_date<=date_sub(curedate(), interval 40 year)
36번
Select *
From patients
Where last_visit_date<=date_sub(curedate(), interval 1 year)
37번
Select count(*)
From patients
Where birth_date between 1980-01-01 and 1989-12-31

38번
Select count(*)
From departments
39번
Select e.name,
d.name
From employees e inner join departments d on e.department_id=d.id
40번
Select e.name
From employees e inner join departments d on e.department_id=d.id
Where d.name=’기술팀’
41번
Select d.name,
Count(e.id)
From employees e left join departments d on e.department_id=d.id
Group by d.id
42번
Select d.name
From employees e left join department d on e.department_id=d.id
Where e.id is null
43번
Select e.name
From employees e inner join department d on e.department_id=d.id
Where d.name=’마케팅팀’

44번
Select o.id,
p.name
From orders o inner join products p on o.product_id=p.id
45번
Select p.id,
Sum(price*quantity) ‘총 매출’
From orders o inner join products p on o.product_id=p.id
Group by p.id
Order by ‘총 매출’ desc
Limit 1
46번
Select p.id,
Sum(quantity) sum_quantity
From product p inner join orders o on p.id=o.product_id
Group by p.id
47번
Select p.name
From orders o inner join products p on o.product_id=p.id
Where order_date>’2023-03-03’
48번
Select p.name,
Sum(quantity) sum_quantity
From products p inner join orders o on p.id=o.product_id
Group by p.id
Order by sum_quantity desc
Limit 1
49번
Select p.id,
Avg(quantity) avg_quantity
From products p inner join orders o on p.id=o.product_id
Group by p.id
50번
Select p.id,
p.name
From product p left join orders o on p.id=o.product_id
Where o.id is null