I would do it like this (taking a stab at this...critique is welcomed):

At 03:17 PM 08.16.2001 +0930, Daniel Falkenberg wrote:
>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;

my $total = 0;
map { $total = $total + $_ } $sth->execute;
print "The sum of the minutes is: $total\n";

I THINK that would work.  I am still somewhat new to Perl myself so if 
someone could validate that for me I'd appreciate it.  I am assuming (now 
probably I shouldn't have buuut porting this shouldn't be hard) that your 
resulting query returns just the minutes.  If it doesn't, then you will 
have to isolate those minutes into a list or array.  Then you can do the 
same thing as above but you would want to replace the '$sth->execute;' with 
'@YOUR_ARRAY' in the map statement.

Remember, map{} is your friend. :)

Thanks everyone IA.

- Jim

>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]



- Jim

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
http://www.perlmonks.org/index.pl?node_id=67861&lastnode_id=67861

-----BEGIN PERL GEEK CODE BLOCK-----      ------BEGIN GEEK CODE BLOCK------
Version: 0.01                             Version: 3.12
P++>*@$c?P6?R+++>++++@$M                  GIT/CM/J d++(--) s++:++ a-
 >++++$O!MA->++++E!> PU-->+++BD            C++++(+) UB++++$L++++$S++++$
$C-@D!>++++(-)$S++++@$X?WP+>++++MO!>+++   P++(+)>+++++ L+++(++++)>+++++$ !E*
+PP+++>++++n-CO?PO!o >++++G               W++(+++) N+ o !K w--- PS---(-)@ PE
 >*(!)$A-->++++@$Ee---(-)Ev++uL++>*@$uB+   Y+>+++ PGP t+(+++)>+++@ 5- X++ R@
 >*@$uS+>*@$uH+uo+w-@$m!                   tv+ b? DI-(+++) D+++(++) G(++++)
------END PERL GEEK CODE BLOCK------      ------END GEEK CODE BLOCK------


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

Reply via email to