PL/SQL Sum

The Sum function returns the summed value of an table column or expression.

Sum syntax

select sum(expression) from table;

Sum example

COURSE_IDNAMEDESCRIPTIONDURATIONPRICE
1SQL 1SQL course for beginners1 week10
2SQL 2SQL course for advanced2 week50
3HTML5Learn HTML 51 week10
4PHPPHP course4 week75
5CSSLearn CSS2 week20
select sum(price) from course;

Result: 165


select sum(price*2) from course;

Result: 330


select sum(price) from course where price between 20 and 50;

Result: 70


select course_id, name, price,
sum(decode(price, 10, price*3, 20, price*4)) mysum 
from course 
where price < = 20
group by course_id, name, price
order by course_id;
COURSE_IDNAMEPRICEMYSUM
1SQL 11030
3HTML51030
5CSS2080