문법 |
목적 |
GROUP_ID함수는 지정된 GROUP BY 결과로부터 중복된 그룹을 구별한다. 이 함수는 질의
결과에서 중복된 GROUPING을 필터링 하는데 유용하다. 유일한 중복 그룹을 식별하기 위해서 ORACLE NUMBER를 반환한다. 이 함수는
GROUP BY구문을 소유한 SELECT문장에서 적용된다. 만약 n이 특정 그룹핑에서 중복이 존재한다면, GROUP_ID는 0~n-1 범위의
수를 반환한다.
예제 |
다음 예제는 sh.countries와 sh.sales의 쿼리로부터 중복된
co.country_region 그룹핑에 1의 값을 할당한다.
SELECT co.country_region, co.country_subregion, SUM(s.amount_sold) "Revenue", GROUP_ID() g FROM sales s, customers c, countries co WHERE s.cust_id = c.cust_id AND c.country_id = co.country_id AND s.time_id = '1-JAN-00' AND co.country_region IN ('Americas', 'Europe') GROUP BY co.country_region, ROLLUP (co.country_region, co.country_subregion); COUNTRY_REGION COUNTRY_SUBREGION Revenue G -------------------- -------------------- ---------- ---------- Americas Northern America 220844 0 Americas Southern America 10872 0 Europe Eastern Europe 12751 0 Europe Western Europe 558686 0 Americas 231716 0 Europe 571437 0 Americas 231716 1 Europe 571437 1
GROUP_ID <1 인 행을 되돌리기 위해서, 문장의 마지막에 다음의 HAVING구문을 추가한다.
HAVING GROUP_ID() < 1