[Zope-DB] ZSQL, sum() and you

Mitch Pirtle mitchy@spacemonkeylabs.com
Mon, 3 Sep 2001 15:33:21 +0200


Hi Zopistas,

The winning answer was from Pavel V. Piankov
[pashah@cosmos-mebel.spb.ru] who had the following angle on life:

<dtml-call "REQUEST.set('total',0)">
<p>
<dtml-in "zsql.dbGetSalary(_,_.None)">
Name: <dtml-var name> - <dtml-var salary> salary<br>
<dtml-call "REQUEST.set('total',total+_.float(salary))">
</dtml-in>
Total: <dtml-var total>
</p>

..and in the process taught me a little about keeping variables around
in DTML -;^>=  Thanks to Pavel for the help, I have agonized over this
for a humiliatingly unacceptable amount of time...

(forehead slap)


> -----Original Message-----
> From: Russell Hires [mailto:rhires@earthlink.net] 
> Sent: Monday, September 03, 2001 15:27
> To: Mitch Pirtle
> Cc: zope-db@zope.org
> Subject: Re: [Zope-DB] ZSQL, sum() and you
> 
> 
> This is a suggestion and a question as I'm a relative Zope 
> Newbie and an SQL 
> Newbie while I'm at it...
> 
> Why not have zope look at the figures returned in the column, 
> and just add 
> 'em up and then divide by the number of times it had a number 
> to go through? 
> Each row.column is an object, right? Is it possible to get 
> the object's 
> value, and then add it, like a "for" loop, but in DTML?
> 
> Hope this is helpful, and if not, I hope I get a good answer myself!
> 
> Russell
> 
> On Monday 03 September 2001 03:43, Mitch Pirtle wrote:
> > > Scavenging the mail folder uncovered Mitch Pirtle's letter:
> > > > Imagine, if you will, a ZSQL method called dbGetEmp
> > >
> > > containing "select
> > >
> > > > * from emp"; and want to also retrieve sum(salary).  
> This is with 
> > > > tables in MySQL.  For the life of me, I cannot find any summing 
> > > > features in Zope - do I gotta do this in Python just to get
> > >
> > > a total on
> > >
> > > > one column?
> > >
> > > maybe i don't understand correctly the problem, but wouldn't...
> > >
> > >       SELECT *, sum(salary) as sum_of_salary FROM emp
> > >
> > > do it?
> >
> > Not in MySQL, and I believe/think/ASSume that's illegal 
> SQL.  (cannot 
> > include GROUP statements within a non-GROUP query or 
> something of the 
> > sort).
> >
> > Basically, I'm returning all rows from a table, and then 
> wanting a sum 
> > from one column.  In PHP, you run the query, display (via loop) the 
> > rows, then calculate the sum of one column (from the same 
> recordset, 
> > without re-running the query).  I cannot figure out the 
> equivalent in 
> > DTML, and am not excited to use python just to get a total.
> >
> > I know how to do this in PL/SQL, but no Oracle here - is 
> there a ZSQL 
> > equivalent?
> >
> > Anybody else out there?  Bueller?
> >
> >
> > _______________________________________________
> > Zope-DB mailing list
> > Zope-DB@zope.org http://lists.zope.org/mailman/listinfo/zope-db
>