Sunday, January 24, 2016

SUM IN SQL: Solve For The Sum of A Column From Database

Instead of solving for the sum of a certain column using PHP or other programming language, you can achieve it by using the SQL SUM function in sql.

Let's say you have the following data on your SALES table and you will solve for the total sales.







Query
select SUM(total) from sales

Output



SUM(total) is not quite a straight forward name for the total sales. You can used an alias to organize your output easily. 

Query using alias
select SUM(total) as TotalSales from sales

The TotalSales on the above query there is you alias for the sum of all total. Or you can remove the as word and the output will still be the same.

Output





SUM IN SQL: Solve For The Sum of A Column  From Database

SUM IN SQL: Solve For The Sum of A Column From Database Rating: 4.5 Diposkan Oleh: Emoblazz

0 comments:

Post a Comment