Hi, I have a SQL query that returns columns of numbers. I'd like to add these numbers together and display the total at the bottom of the page under each column. My question is, as I move through the returned rows how do I add the current value of a field to the sum of all previous values of a field? I'm sure this is very easy - but my mind is fried from the work week and I'm just not thinking about this clearly. I've searched the lists and I can't put the right combination of search phrases together. I suspect this will be a python script solution rather than DTML. Pointers to docs or how-tos I've overlooked would be helpful. Thanks! Mark
Why not just split your query up, one that returns the rows and another that returns the totals. Use SQL for what it's good at. hth ----- Original Message ----- From: "Mark Langkau" <mark.langkau@pbmplus.com> To: <zope@zope.org> Sent: Saturday, July 21, 2001 12:26 AM Subject: [Zope] How to I get column totals?
Hi,
I have a SQL query that returns columns of numbers. I'd like to add these numbers together and display the total at the bottom of the page under each column. My question is, as I move through the returned rows how do I add the current value of a field to the sum of all previous values of a field?
I'm sure this is very easy - but my mind is fried from the work week and I'm just not thinking about this clearly. I've searched the lists and I can't put the right combination of search phrases together. I suspect this will be a python script solution rather than DTML. Pointers to docs or how-tos I've overlooked would be helpful.
Thanks! Mark
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Phil, Yes, you are right. What really prompted my question was suddenly realizing that I hadn't ever tried to do any math with Zope and couldn't figure out how to add these columns. 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. I could use some links to basic math with Zope I guess. Cheers, Mark Phil Harris wrote:
Why not just split your query up, one that returns the rows and another that returns the totals.
Use SQL for what it's good at.
hth ----- Original Message ----- From: "Mark Langkau" <mark.langkau@pbmplus.com> To: <zope@zope.org> Sent: Saturday, July 21, 2001 12:26 AM Subject: [Zope] How to I get column totals?
Hi,
I have a SQL query that returns columns of numbers. I'd like to add these numbers together and display the total at the bottom of the page under each column. My question is, as I move through the returned rows how do I add the current value of a field to the sum of all previous values of a field?
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.
It's not Zope per se, but I'd do it in Python -- objectValues() returns a list, use len() to get its length, etc. Or, for a more generic case, which would probably be done far better in PythonScript (and completely untested): <dtml-call "REQUEST.set('a',1)"> <dtml-call "REQUEST.set('b',2)"> <dtml-call "REQUEST.set('c',a+b)"> -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
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
participants (4)
-
Joel Burton -
Mark Langkau -
Mike Renfro -
Phil Harris