What should be a Select query with SUM calculation of a column for every row?
I have a Column Amount, I will get multiple rows with different values in that Amo开发者_如何学运维unt column. I need a select query such that I get the SUM of all these amounts as an output.
Thanks And Regards
Use the SUM aggregrate function:
SELECT SUM(Amount) AS Total
FROM yourtable
The result will contain a single row, containing the total sum for the column.
This:
SELECT SUM(t.amount)
FROM YOUR_TABLE t
...will return a single value, the sum of all the values in the amount column. If you want to see the sum for different groups of values, you need to add a GROUP BY clause to the query:
SELECT SUM(t.amount)
FROM YOUR_TABLE t
GROUP BY t.column
精彩评论