If all you want to do is get a total of all the minutes in the table, work
smarter, not harder. Let SQL do the work for you. In your select statement
you will want to use the function sum. So something like so:

$sth = $dbh ->prepare( qq{       SELECT      sum(minutes)
                               FROM        table
                               WHERE       status = 'COMPLETE'
                               } ) || die $dbh->errstr; ;

After execution, the query will return one row and one column with the sum
of all the minutes that meet the conditional.

Hope this helps.

Peter Hanson
-Database Administrator
-Programmer
-Marketing Manager

Want to make your traffic explode and your website a success?
http://www.source1results.com

-----Original Message-----
From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 16, 2001 1:47 AM
To: Beginners (E-mail)
Subject: Calculation the total of my column


List,

I have a problem here that I am having a little bit of trouble trying to
resolve.  Firstly I have a Perl script that connects to a PostgreSQL
database using the DBI module.  I want to be able to SELECT a column from
the database and return the total result.

For example if I do the following...

$sth = $dbh ->prepare( qq{       SELECT      minutes
                               FROM        table
                               WHERE       status = 'COMPLETE'
                               } ) || die $dbh->errstr; ;
$sth->execute;

The minutes attribute is of type integer.  I want to be able to calculate
the total for the attribue minutes.  So far the result for the SQL query
above is...

minutes
--------
   30
   45
    5
    5
   15
   25
   15
    5
   25
   25
(10 rows)


How would I with Perl now count the column above and return a result?

Any ideas would help imensly.

kind regards,

Daniel Falkenberg

==============================
VINTEK CONSULTING PTY LTD
(ACN 088 825 209)
Email:  [EMAIL PROTECTED]
WWW:    http://www.vintek.net
Tel:    (08) 8523 5035
Fax:    (08) 8523 2104
Snail:  P.O. Box 312
        Gawler   SA   5118
==============================


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to