❓ 문제
- 직책이 Technique Leader인 연도별 퇴사자 수
- first_name의 시작 알파벳이 같은 사람들의 알파벳과 평균 연봉 (알파벳 순 정렬)
- emp_no가 10200번대에 남자인 사람들의 여태 받은 총 급여
✔️ 풀이
-- 직책이 Technique Leader인 연도별 퇴사자 수를 출력하라
select count(emp_no), year(to_date)
from titles
where title = 'Technique Leader'
and to_date not like '9999-01-01'
group by year(to_date)
order by year(to_date) desc;
-- first_name의 시작 알파벳이 같은 사람들의 알파벳과 평균 연봉을 구하시오 (알파벳 순 정렬)
select left(first_name, 1) as n, avg(s.salary)
from employees as e
join salaries as s
on e.emp_no = s.emp_no
group by n
order by n asc;
-- emp_no가 10200번대에 남자인 사람들의 여태 받은 총 급여를 뽑아라
select emp_no, sum(salary)
from salaries
where emp_no like '102__'
and emp_no in (select emp_no from employees
where gender = 'M')
group by emp_no;
💡 문자열 자르기
SUBSTRING("문자열", "시작위치", "길이") : 지정한 위치에서 지정한 문자열 길이만큼 자를 때 사용
LEFT("문자열", "길이") : 왼쪽에서부터 지정한 문자열의 길이만큼 자를 때 사용
RIGHT("문자열", "길이") : 오른쪽에서부터 지정한 문자열의 길이만큼 자를 때 사용