Oracle AVG Function


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

A few examples of the AVG function.


Copy this code and paste it in your HTML
  1. --AVG Function
  2.  
  3. SELECT * FROM student;
  4.  
  5. --Example 1
  6. SELECT AVG(fees_paid) AS avg_fees_paid
  7. FROM student;
  8.  
  9. --Example 2
  10. SELECT TO_DATE(ROUND(AVG(TO_NUMBER(TO_CHAR(enrolment_date, 'J')))), 'J') AS avg_date
  11. FROM student;
  12.  
  13.  
  14. --Example 3
  15. SELECT gender, AVG(fees_paid) AS avg_fees_paid
  16. FROM student
  17. GROUP BY gender;
  18.  
  19.  
  20. --Example 4
  21. SELECT gender, AVG(fees_paid) AS avg_fees_paid
  22. FROM student
  23. GROUP BY gender
  24. HAVING AVG(fees_paid) > 200;
  25.  
  26.  
  27. --Example 5
  28. SELECT TO_CHAR(enrolment_date, 'MON') AS ENROLMENT_MONTH,
  29. AVG(fees_paid) AS avg_fees_paid
  30. FROM student
  31. GROUP BY TO_CHAR(enrolment_date, 'MON');

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.