Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - SUM(Column) * QtyColumn

Tags:

sql

sql-server

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
like image 376
PsychoDUCK Avatar asked May 27 '12 21:05

PsychoDUCK


2 Answers

Here you go

SELECT SUM(Amount*Quantity) as total, SUM(Quantity) as totalQuantity
like image 111
buckley Avatar answered Sep 22 '22 01:09

buckley


select sum(Amount * Quantity) as total, 
       sum(Quantity) as totalQuantity
from your_table
like image 40
juergen d Avatar answered Sep 18 '22 01:09

juergen d