Posted By

bbrumm on 03/14/17


Tagged

sql Oracle


Versions (?)

Oracle GROUP_ID Function


 / Published in: SQL
 

URL: http://www.databasestar.com/oracle-group_id

A few examples of the GROUP_ID function.

  1. SELECT * FROM student;
  2.  
  3. SELECT address_state,
  4. TO_CHAR(enrolment_date, 'MON') AS enrolment_month,
  5. SUM(fees_paid)
  6. FROM student
  7. GROUP BY address_state, TO_CHAR(enrolment_date, 'MON');
  8.  
  9.  
  10. SELECT address_state,
  11. TO_CHAR(enrolment_date, 'MON') AS enrolment_month,
  12. SUM(fees_paid),
  13. GROUP_ID()
  14. FROM student
  15. GROUP BY address_state, ROLLUP(address_state, TO_CHAR(enrolment_date, 'MON'))
  16. ORDER BY address_state, TO_CHAR(enrolment_date, 'MON'), GROUP_ID();
  17.  
  18.  
  19.  
  20. SELECT address_state,
  21. TO_CHAR(enrolment_date, 'MON') AS enrolment_month,
  22. SUM(fees_paid),
  23. GROUP_ID()
  24. FROM student
  25. GROUP BY address_state, ROLLUP(address_state, TO_CHAR(enrolment_date, 'MON'))
  26. HAVING GROUP_ID() = 0
  27. ORDER BY address_state, TO_CHAR(enrolment_date, 'MON'), GROUP_ID();

Report this snippet  

You need to login to post a comment.