Using more than one compute clause  Using different aggregates in the same compute clause

Chapter 3: Using Aggregates, Grouping, and Sorting

Applying an aggregate to more than one column

One compute clause can apply the same aggregate to several columns. 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 
compute sum(price), sum(advance) by type
type      price            advance 
--------- ---------------- ---------------
mod_cook              2.99       15,000.00 
mod_cook             19.99            0.00 
 
Compute Result:
--------------- ---------------
          22.98       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 
 
Compute Result:
--------------- ---------------
          47.89       19,000.00 
 
(7 rows affected) 

Remember, the columns to which the aggregates apply must also be in the select list.





Copyright © 2005. Sybase Inc. All rights reserved. Using different aggregates in the same compute clause

View this book as PDF