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)
精彩评论