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 salesOutput
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
0 comments:
Post a Comment