Sunday, December 29, 2013

SQL Query Totals Grouping Subtotals

I have a table with the following fields;



ID “primary Key”, SystemNum, PurchaseDescription, ModelNumber, Brand, Quantity, Cost




I’m trying to wright a query that returns all the fields and has a calculated field Quantity * Cost = ‘Amount’


I’ve got this far no problem it works.




SELECT [ID]
,[SystemNum]
,[PurchaseDescription]
,[ModelNumber]
,[Brand]
,[Quantity]
,[Cost]
,Quantity*Cost AS 'Amount'

FROM [Equipment].[dbo].[SystemsComponents]





I also need to group by SystemNum and get a total of the Amount for each group. I can’t figure out how to group it without getting an error.





why767


No comments:

Post a Comment