Oracle GROUP_ID Function


/ Published in: SQL
Save to your folder(s)

A few examples of the GROUP_ID function.


Copy this code and paste it in your HTML
  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();

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.