One COMPUTE BY clause can apply the same aggregate function to several columns. Remember that the columns to which the aggregate functions apply must also be in the select list. This query finds the sum of the prices and advances for each type of cookbook:
SELECT type, price, advance |
FROM titles |
WHERE type LIKE '%cook' |
ORDER BY type, price |
COMPUTE SUM(price), SUM(advance) BY type |
type price advance ------------ -------------------------- -------------------------- mod_cook 2.99 15,000.00 mod_cook 19.99 0.00 sum ========================== 22.98 sum ========================== 15,000.00 type price advance ------------ -------------------------- -------------------------- trad_cook 11.95 4,000.00 trad_cook 14.99 8,000.00 trad_cook 20.95 7,000.00 sum ========================== 47.89 sum ========================== 19,000.00 (7 row(s) affected)