OM The Eternity
OM The Eternity

Reputation: 16204

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 Amount column. I need a select query such that I get the SUM of all these amounts as an output.

Thanks And Regards

Upvotes: 0

Views: 443

Answers (2)

OMG Ponies
OMG Ponies

Reputation: 332581

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

Upvotes: 1

Mark Byers
Mark Byers

Reputation: 838146

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.

Upvotes: 2

Related Questions