Database/mysql
[1일1쿼리] 오늘이 생일인 사람이 각 부서마다 몇명인가 ?
JINJINC
2025. 1. 8. 17:01
728x90
반응형
select
right(e.birth_date,5) as 'birthDay' ,
d.dept_name,
count(e.emp_no) as 'count'
from employees as e
join dept_emp as m on m.emp_no = e.emp_no
left join departments as d on d.dept_no = m.dept_no
where right(e.birth_date,5)= substring(now(),6,5)
and m.to_date = '9999-01-01'
group by d.dept_name
with rollup
order by d.dept_name desc, e.emp_no asc;728x90
반응형