프로그래밍/MYSQL

my sql 최소값min(),최대값max(), group by ,소계 with rollup

타코코딩 2023. 10. 13. 18:29

--최대연봉, 최저연봉      

SELECT min(salary),max(salary)  FROM employee



-- 가장빠른 입사일, 가장최근 입사일

SELECT min(hire_date),max(hire_date)  FROM employee


-- 입사월별 사원수, 최대연봉, 최저연봉

SELECT substr(hire_date,6,2) 입사월, min(salary),max(salary)  FROM employee GROUP BY 입사월 ORDER BY 입사월


 -- 년도별, 각 부서의 사원수와 총연봉을 출력

SELECT LEFT(hire_date,4)  year,ifnull(dept_id,'합계') ,sum(salary)  FROM employee GROUP BY YEAR,dept_id WITH rollup;