Joint Use of Totals and Groups
If totals are used with groups and a list of aggregate functions is not specified for totals, it will be generated automatically from aggregate fields of the selection list. If a query contains join, aggregate functions will be used from the first query.
Example:
SELECT Doc.Product, Doc.Reference.Recipient, SUM(Doc.Count)
FROM Document.ExpInvoice.Contents AS Doc
GROUP BY Doc.Product, Doc.Reference.Recipient
TOTALS BY Doc.Product
Query result:
Product
Recipient
Count
Faucet
84
Faucet
Urupinsk products
32
Faucet
“Master” Store
8
Faucet
“Giant” Store
44
Plunger
20
Plunger
Urupinsk products
5
Plunger
“Master” Store
1
Plunger
“Giant” Store
14
Table
26
Table
Urupinsk products
1
Table
“Furniture” Store
15
Table
“Giant” Store
10
Chair
108
Chair
Urupinsk products
16
Chair
“Furniture” Store
55
Chair
“Master” Store
5
Chair
“Giant” Store
32