SQL SUM

SQL SUM

The SQL SUM function returns the sum value of all rows in a select query.

SUM syntax

SELECT SUM(table_column)
FROM table_name;

SUM example

Coder books table

IDTitlePriceDescription
1Learn SQL20Learn SQL language
2Learn MySQL22Learn MySQL language
3HTML book17Learn HTML
4Learn PHP20Introduction to PHP
5Learn PHP20PHP course
SELECT SUM(price) 
FROM coder_books;

Result

99

SELECT price, SUM(price) sum_price
FROM coder_books
GROUP BY price
HAVING count(*) > 1;

Result

Pricesum_price
2060