/ Published in: SQL
A few examples of the SUM function.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SELECT * FROM student; --Example 1 SELECT SUM(fees_paid) AS SUM_FEES_PAID FROM student; --Example 2 SELECT SUM(fees_paid) AS SUM_FEES_PAID FROM student WHERE fees_paid <> fees_required; --Example 3 SELECT EXTRACT(MONTH FROM enrolment_date) AS ENROLMENT_MONTH, SUM(fees_paid) AS SUM_FEES_PAID FROM student GROUP BY EXTRACT(MONTH FROM enrolment_date); --Example 4 SELECT SUM(fees_paid) AS SUM_FEES_PAID, SUM(fees_paid * 0.1) AS SUM_TAX FROM student; --Example 5 SELECT SUM(fees_required - fees_paid) AS FEES_OWING FROM student; --Example 6 SELECT first_name, last_name, EXTRACT(MONTH FROM enrolment_date) AS ENROLMENT_MONTH, SUM(fees_paid) OVER (PARTITION BY (EXTRACT(MONTH FROM enrolment_date))) AS FEES_MONTH FROM student; --Example 7 SELECT SUM(fees_paid) AS SUM_ALL_FEES, SUM(DISTINCT fees_paid) AS SUM_DISTINCT_FEES FROM student;
URL: http://www.databasestar.com/oracle-sum/