Sql server 对子查询求和

Sql server 对子查询求和,sql-server,Sql Server,我的问题是: select sum(round(fQtyOut*(select fCostAVRR from item where item.ccode=ItmUpTrn.cItemCode),3)) from ItmUpTrn where cInvoiceNo= 'C2-19584' 返回: 无法对包含聚合或子查询的表达式执行聚合函数 我只需要一个字段和总值。我该怎么做呢?换成这样怎么样 SELECT round(sum(ItmUpTrn.fQtyOut*item.fCostAVR

我的问题是:

select  sum(round(fQtyOut*(select fCostAVRR from item where item.ccode=ItmUpTrn.cItemCode),3)) from ItmUpTrn
where cInvoiceNo=  'C2-19584'
返回:

无法对包含聚合或子查询的表达式执行聚合函数


我只需要一个字段和总值。我该怎么做呢?

换成这样怎么样

SELECT 
  round(sum(ItmUpTrn.fQtyOut*item.fCostAVRR),3) 
  --sum(round(ItmUpTrn.fQtyOut*item.fCostAVRR,3)) 
FROM ItmUpTrn
JOIN item
on item.ccode=ItmUpTrn.cItemCode
WHERE ItmUpTrn.cInvoiceNo=  'C2-19584'

请注意,我会在求和后四舍五入。它更快更准确,如果这不是你需要的,你可以把它改回来

你搜索过这个错误的网站了吗,因为有很多关于它的帖子:非常感谢你,你是我的救世主