Oracle
오라클 group by having 간단 설명 및 예제
뽀우맨
2024. 3. 20. 15:30
having 절은 보통 group by 다음에 사용하며, group by의 결과에 추가적인 조건 걸 때 사용합니다.
(단독으로 사용가능하지만 일반적이지는 않습니다.)
아래의 예를 보면 쉽게 이해 될 겁니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | select A.Name, avg(A.Val), max(A.Val), count(A.Val), sum(A.Val) from ( select 'A' as Name, 10 as Val from dual union select 'A', 20 from dual union select 'B', 100 from dual union select 'B', 200 from dual union select 'B', 300 from dual ) A group by A.Name having sum(A.Val) > 500 --having avg(A.Val) > 100 --having count(A.Val) > 2 | cs |
그럼...