[Zope] How to I get column totals?

Joel Burton jburton@scw.org
Sat, 21 Jul 2001 13:03:26 -0400 (EDT)


On Sat, 21 Jul 2001, Mike Renfro wrote:

> On Fri, Jul 20, 2001 at 07:15:29PM -0500, Mark Langkau wrote:
> 
> > Let's say I'm not using a SQL query and I want to count the number
> > of objects of certain types in a folder, present the individual
> > totals, then add them into a combined total of all objects. Or let's
> > say I'm running several SQL queries, perhaps against different
> > databases (Oracle, MySQL, etc.) and I'd like to total the results of
> > those.

Perhaps I'm missing something, but, if I understand correctly,
you have a table like:

Part     Item #    Cost
WidgetA  1         $5
WidgetB  2         $7
WidgetC  3         $9

To show all of these, and have total information at the bottom, you could:

<dtml-in widgetsSQLMethod>
  <dtml-if sequence-start>
    <table>...table header here...
  </dtml-if>
    <tr>... display widgets here ...</tr>
  <dtml-if sequence-end>
    <tr><td colspan=3><dtml-var total-cost></td></tr>
  </dtml-if>
</dtml-in>

where total-xxx gives you the sum of that variable in a dtml-in
loop. (There's also count-, min-, max-, mean-, variance-,
standard-deviation, and n-variant versions of variance and
standard-deviation.)

hth,
-- 
Joel Burton   <jburton@scw.org>
Director of Information Systems, Support Center of Washington