开发者

What should be a Select query with SUM calculation of a column for every row?

开发者 https://www.devze.com 2023-02-04 23:09 出处:网络
I have a Column Amount, I will get multiple rows with different values in that Amo开发者_如何学运维unt column.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消