inblog logo
|
harimmon
    데이터베이스

    [Database] 15. 집합

    백하림's avatar
    백하림
    Feb 28, 2025
    [Database] 15. 집합
    -- 집합 -- 1. union all (통으로 붙인다. 컬럼 개수가 같아야 한다.중복된다) select sum(sal), deptno from emp where deptno = 10 union all select sum(sal), deptno from emp where deptno = 20 union all select sum(sal), deptno from emp where deptno = 30 union all select sum(sal), null from emp;
    notion image
    -- group by로 묶기 select sum(sal), deptno from emp group by deptno union all select sum(sal), null from emp;
    notion image
    -- 2. union (합집합 - 중복을 제거한다(연산을 한 번 더 해서 느리다.)) -- 20이 중복되었지만 제거하고 출력되었다. select * from dept where deptno > 10 -- 20,30,40 union select * from dept where deptno < 30; -- 10,20
    notion image
    -- 3. intersect (교집합) select * from dept where deptno > 10 INTERSECT select * from dept where deptno < 30;
    notion image
    -- 4. EXCEPT (차집합 - 툴이 80% 정도 정신 못 차림) select * from dept where deptno > 10 EXCEPT select * from dept where deptno < 30;
    notion image
    Share article

    harimmon

    RSS·Powered by Inblog