Possible Duplicate:
Insert line into a query result (sum)
I have a report that shows products that customers have ordered, along with their prices:
CompanyA Product 7 14.99
CompanyA Product 3 45.95
CompanyA Product 4 12.00
CompanyB Product 3 45.95
CompanyC Product 7 14.99
CompanyC Product 3 45.95
I'd like to insert a line that sums each company's order, like this:
CompanyA Product 7 14.99
CompanyA Product 3 45.95
CompanyA Product 4 12.00
Total: 72.94
CompanyB Product 3 45.95
Total: 45.95
CompanyC Product 7 14.99
CompanyC Produ开发者_Go百科ct 3 45.95
Total: 60.94
Here's some code that shows the basic structure of the query I have:
SELECT company
, product
, price
FROM companyMaster
ORDER BY company,
, product,
, price;
Does anyone know how to do this? I'm writing this in Transact-SQL (Microsoft SQL Server).
you need two queries with different "group by" one is by customer, product and the other is by customer only.
精彩评论