

select * from dept;
dept 테이블에 있는 deptno가 40번인 컬럼이
emp 테이블에는 없음

emp 테이블에 deptno가 40번인 컬럼이 없기 때문에
deptno가 40번인 loc가 BOSTON인 컬럼이 출력되지 않음
select e.ename, d.loc
from emp e, dept d
where e.deptno = d.deptno;
답:
select e.ename, d.loc
from emp e, dept d
where e.deptno(+) = d.deptno;
💡
OUTER JOIN 싸인(+)은 데이터가 모자라게 나오는 쪽에 붙여줌
ㄴ 데이터가 없는 쪽에 붙여줌
insert into emp(empno, ename, sal, deptno)
values(3921, 'JACK', 3400, 70);
commit;

select e.ename, d.loc
from emp e, dept d
where e.deptno = d.deptno(+);

select d.loc, sum(e.sal)
from emp e, dept d
where e.deptno = d.deptno
group by d.loc;

select d.loc, sum(e.sal)
from emp e, dept d
where e.deptno(+) = d.deptno
group by d.loc;
cmd에 붙여넣기
@demo
alter table emp add emp_kind varchar2(1) default 1 not null;
update emp set emp_kind = case when mod(empno, 2) = 1 then 1 else 2 end;
create table emp_kind1 as
select empno, ename, sal + 200 as office_sal
from emp where emp_kind = '1';
create table emp_kind2 as
select empno, ename, sal + 200 as sal
from emp where emp_kind = '2';
alter table emp_kind1 add constraint pk_emp_kind1 primary key(empno);
alter table emp_kind2 add constraint pk_emp_kind2 primary key(empno);
alter table emp drop column sal;
select * from emp;
select * from emp_kind1;
select * from emp_kind2;
테이블 3개 outer join

select e.empno, e.ename, ek1.office_sal, ek2.sal
from emp e, emp_kind1 ek1, emp_kind2 ek2
where e.empno = ek1.empno(+)
and e.empno = ek2.empno(+);

select deptno, sum(sal)
from emp
group by deptno;

select deptno, sum(sal)
from emp
group by rollup(deptno);

select d.loc, sum(e.sal)
from emp e, dept d
where e.deptno = d.deptno
group by rollup(d.loc);

select d.loc, listagg(e.ename,',') within group (order by e.ename asc)
from emp e, dept d
where e.deptno = d.deptno
group by d.loc;