group by 그룹화 하고 싶은 칼럼 / 조건
select deptno,job,
round(avg(sal),1) as '직급별 평균급여'
from emp
group by deptno,job
having sal≥2500
order by deptno asc, job desc;
select job, deptno, round(avg(sal),1), count(ename)
from emp
where sal ≥ 2000
group by deptno, job
having avg(sal) ≥ 3000
order by deptno asc, job desc;
: 가상의 테이블
불러오는 값은 딱히 없고 select 만 보고싶을 때
select round(1020.13929, 1) from dual;
: 2개의 테이블을 한번에 조회.
컬럼이 같아야하고 이름을 지정해줘야함
ex) emp / dept deptno 컬럼으로 테이블 조인
select e.*, d.* from emp e, dept d where e.deptno = d.deptno;
: 쿼리 안에 (쿼리)를 넣는다 ()가 먼저 실행
ex) 사원 중에서 평균 월급보다 많이 월급받는 사원의 이름
select ename from emp where sal > (select avg(sal) from emp);
ex) 서브쿼리와 테이블 조인
select * from emp e, dept d where e.deptno = d.deptno and e.sal>(select avg(sal) from emp) and e.deptno = 20;