- From: Per Bothner <per@bothner.com>
- Date: Thu, 24 Jan 2002 11:13:46 -0800
- To: "Tolkin, Steve" <Steve.Tolkin@FMR.COM>
- CC: www-ql@w3.org
Tolkin, Steve wrote: > Your "guess" about what is a traditional control break report > is accurate. There are typically several levels of > control breaks, including one global (grand total) level. > In addition to totals and subtotals other measures are often > desired as well, e.g. average, maximum, etc. maybe an extension to 'for' might be a good start: for $VAR in DATA group-by [$GVAR :=] COND return BODY This loops through the sequence DATA. For each value, COND is evaluated, with the context item '.' set to that value, similar to how sortby works. $GVAR is bound to the value of COND. Each group consists of those elements that have the same $GVAR (equal-by-value, not identity of course). For each group, BODY is evaluated, with $VAR bound to the *group* (as a sequence), and $GVAR bound to the grouping value. for example: for $cust in customers group-by $state := address/state return <line>Start customers in: {$state}<line>, for $dot in $cust return <line>{format-customer(.)}</line>, <line>Number of customers in {$state}: {count($cust)}</line> This could be processed in a single pass, assuming body does not reference the entire $VAR as a sequence, except to iterate through it once, or for aggregate operations at the end. One could do this using a special 'group-by' function, but the syntax would be pretty bad and harder to optimize. A special operator (like sortby) has the problem that it woudl need to return sequencs of sequences, which xquery doesn't have, so we'd have to wrap each group in an element. That might be ok. I haven't thought about how to handle running totals, but we could probably work something out. -- --Per Bothner per@bothner.com http://www.bothner.com/per/
Received on Thursday, 24 January 2002 14:12:59 UTC