开发者

Insert line into a query result (sum) [duplicate]

开发者 https://www.devze.com 2023-02-27 06:21 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Insert line into a query result (sum)
This question already has answers here: Closed 11 years ago.

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.

0

精彩评论

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