Return to Snippet

Revision: 71347
at February 20, 2017 08:36 by bbrumm


Initial Code
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;

Initial URL
http://www.databasestar.com/oracle-sum/

Initial Description
A few examples of the SUM function.

Initial Title
Oracle SUM Function

Initial Tags
sql, Oracle

Initial Language
SQL