There is a table (T1) that contains 1 record per transaction, ocurred in a group of sales units. Among others, it has the following fields:
UNIT_ID (Id of sales unit), TRANS_AMT (Trans amount).
The requirement is to calculate the total of transactions in quantity and amount by unit of sale, including the ratios (or percentages) upon the overall totals.
The next statement was used:
SELECT SELECT A.UNIT_ID, QTY, QTY / TQTY, AMT, AMT / TAMT
FROM ( SELECT UNIT_ID, COUNT(*) QTY, SUM (TRANS_AMT) AMT
FROM T1 GROUP BY UNIT_ID ) A,
( SELECT COUNT(*) TQTY, SUM (TRANS_AMT) TAMT
FROM T1 ) B
ORDER BY A.UNIT_ID