开发者

How to groupy by Column1 and multiply Column2 with Count(*)?

开发者 https://www.devze.com 2023-04-04 06:49 出处:网络
this is what i\'m trying to achieve: SELECTCOUNT(*) * dd.Material_Quantity as [Count], tabSparePart.SparePartName

this is what i'm trying to achieve:

SELECT  COUNT(*) * dd.Material_Quantity as [Count], tabSparePart.SparePartName
FROM         tabDataDetail AS dd INNER JOIN
                      tabSparePart ON dd.fiSparePart = tabSparePart.idSparePart
WHERE    dd.Reused_Indicator = 1
GROUP BY tabSparePart.SparePartName
ORDER BY Count DESC, tabSparePart.SparePartName

Count all sparepart occurences and multiply them with their c开发者_StackOverflow社区orresponding Material_Quantity value. But i get following error:

8118: Column 'tabDataDetail.Material_Quantity' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.

How can i multiply both values meaningfully? Would a simple SUM or AVG give the correct result? For example: COUNT(*) * AVG(dd.Material_Quantity) as [Count]


If you're looking for the sum of quantities, you could use sum:

SUM(dd.Material_Quantity)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号