SQL Server - SUM(列)* QtyColumn

标签 sql sql-server

是否可以在不返回多行(Group BY)的情况下获取总计?

示例:

数据:

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

我希望结果位于 1 行中:

total       totalQuantity 
150         3

最佳答案

给你

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

关于SQL Server - SUM(列)* QtyColumn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10777458/

相关文章:

sql - Postgres,plpgsql : Is there a way to connect to other DB from inside of a stored procedure?

mysql - NOT FOUND Mysql 中更新过程的错误处理

sql - 将数据库缩小到一定大小

javascript - 如何在 Node.JS 中为 MSSQL 创建准备好的语句?

sql - 仅选择 Varchar 列中的数字

sql-server - 需要在 SSIS 中附加 excel 文件

sql-server - 如何更新activeX脚本任务

mysql - 如何从一张表中选择用户尚未选择的所有记录?

mysql - 是否将图像存储在 SQL 中?

sql - 在应用程序的数据库存储过程中使用 MSDB 存储过程