Sql SUM() Function.

Learn Prg.

The SUM() Function

The SUM() function returns the total sum of a numeric column.

SQL SUM() Syntax

SELECT SUM(column_name) FROM table_name;

A simple syntax to get final result in single field.

SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;
prd_id	prd_name	prd_costA	prd_costB	prd_costC
1       mango jam	   15223	    4424	73239
2       custard jam	   1523	            144 	7339
3       Apple jam	   154	            145	        789
4       bananna jam	   153	            1423	78232
5       perry jam	   153	            1454	7839

A bit more complex syntax to get the total of three columns and arranging them according to their respective id.

SUM(`prd_costA`+`prd_costB`+`prd_costC`)AS tcs
FROM `product_prd` GROUP BY `prd_id`

View original post


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s