PsychoDUCK
PsychoDUCK

Reputation: 1103

SQL Server - SUM(Column) * QtyColumn

Is it possible to get the total without returning it in multiple rows (Group BY)?

Example:

Data:

ID    Amount   Quantity
1     50       1 
2     50       2
select sum(Amount) * Quantity, SUM(Quantity) as totalQuantity 
  from tbl

I want the results to be in 1 row:

total       totalQuantity 
150         3

Upvotes: 6

Views: 13781

Answers (2)

buckley
buckley

Reputation: 14119

Here you go

SELECT SUM(Amount*Quantity) as total, SUM(Quantity) as totalQuantity

Upvotes: 7

juergen d
juergen d

Reputation: 204884

select sum(Amount * Quantity) as total, 
       sum(Quantity) as totalQuantity
from your_table

Upvotes: 4

Related Questions