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 line:

 total totalQuantity 150 3 
+4
source share
2 answers

Here you go

 SELECT SUM(Amount*Quantity) as total, SUM(Quantity) as totalQuantity 
+6
source
 select sum(Amount * Quantity) as total, sum(Quantity) as totalQuantity from your_table 
+4
source

Source: https://habr.com/ru/post/1414641/


All Articles