Listing more than one column after the by keyword affects the query by breaking a group into subgroups and applying the specified row aggregate to each level of grouping. For example, this query finds the sum of the prices of psychology books from each publisher:
select type, pub_id, price from titles where type = "psychology" order by type, pub_id, price compute sum(price) by type, pub_id
type pub_id price ----------- ------- ------------- psychology 0736 7.00 psychology 0736 7.99 psychology 0736 10.95 psychology 0736 19.99 Compute Result: --------------- 45.93 type pub_id price ----------- ------- ------------- psychology 0877 21.59 Compute Result: --------------- 21.59 (7 rows affected)
Copyright © 2005. Sybase Inc. All rights reserved. |