Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: DBI:CSV SQL parsing problem

by ikegami (Patriarch)
on Nov 05, 2007 at 16:45 UTC ( [id://649058]=note: print w/replies, xml ) Need Help??


in reply to DBI:CSV SQL parsing problem

Workaround:
my $sth = $dbh->prepare("SELECT AVG(col2), AVG(col3) FROM mydata.csv") +; $sth->execute(); my @avgs = $sth->fetchrow_array(); my $avg = $avgs[0] + $avgs[1];

Replies are listed 'Best First'.
Re^2: DBI:CSV SQL parsing problem
by jZed (Prior) on Nov 05, 2007 at 17:00 UTC
    Something like that might work. OTOH, I'm not totally sure what AVG(col1 +col2) should produce or whether it would be same as what you suggest. For example, since NULLs are eliminated, the two columns may have a different Count.
Re^2: DBI:CSV SQL parsing problem (NULL)
by tye (Sage) on Nov 05, 2007 at 17:00 UTC

    Note that this gives different results if ever only one of col2 and col3 are NULL.

    - tye        

      No worries there, all columns have the same number of (non NULL) values.
Re^2: DBI:CSV SQL parsing problem
by rlewisuk (Initiate) on Nov 05, 2007 at 19:38 UTC
    Thanks ikegami
    This might be an option. I have tried
    SELECT AVG(col2) + AVG(col3)...
    Without success. If I use
    my $avg = $avgs[0] + $avgs[1];
    I'll first have to parse the SELECT statement for +,-,* and / and replace with commas and do the operation afterwards, but it certainly seems doable.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://649058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-03-19 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found