[IT]/MySQL
연습
givemebro
2020. 3. 20. 17:36
반응형
show databases;
use 인사급여;
show tables;
select *
from 사원;
select count(*), count(퇴사일자)
from 사원;
## 직급별 인원수
select 직급, count(*) as 인원수
from 사원
group by 직급;
## 직급별 인원 및 평균 월급
select 직급,count(*) as 인원수, avg(월급여)
from 사원
group by 직급;
## 급여 구분에 따른 평균 월급
select 급여구분, count(*), avg(월급여)
from 사원
group by 급여구분;
## 입사 년도별 평균 월급
select year(입사일자) as 입사년도, count(*) as 인원수, avg(월급여) as 평균월급
from 사원
group by year(입사일자)
order by 평균월급;
## 년도별, 직급별 몇명
select year(입사일자) as 입사년도, 직급 ,count(*) as 인원수,avg(월급여) as 평균월급
from 사원
group by year(입사일자), 직급
order by 입사년도, 직급;
## order
select *
from 사원
order by if(직급='대리','1_대리',if(직급='과장','2_과장','3_차장')) desc, 입사일자;
## 부서명 출력
select 사원.*,부서명
from 사원 inner join 부서
where 사원.부서코드=부서.부서코드
order by 부서명;
## 월별 급여지급 합계
select*
from 급여지급;
select 급여월, sum(월급여) as 합
from 급여지급
group by 급여월
order by 합
;
## 성과금 out join / null도 출럭
select 사원.사원번호, 사원.사원명, 급여지급.급여월, 급여지급.성과급
from 사원 left join 급여지급
on 사원.사원번호 = 급여지급.사원번호
order by 사원명
;
select 사원명, sum(급여지급.월급여) as 총급여
from 사원 left join 급여지급
on 사원.사원번호 = 급여지급.사원번호
group by 사원. 사원번호, 사원.사원명
order by 총급여 desc;
select 사원명, sum(급여지급.성과급) as 총성과급
from 사원 left join 급여지급
on 사원.사원번호 = 급여지급.사원번호
group by 사원. 사원번호, 사원.사원명
order by 총성과급 desc;
select 사원.사원명, 급여지급.성과급
from 사원 inner join 급여지급
on 사원.사원번호 = 급여지급. 사원버호;
select*
from 급여지급;
## 지역별 월별 총 급여 *********************************************check
select 부서.지역,급여지급.급여월, sum(월급여) 총급여
from 부서, 사원, 급여지급
where 부서.부서코드=사원.부서코드
group by 부서.지역, 급여지급.급여월
order by 총급여;반응형