optimizing a query
Randy Burke <uncle.ranny <at> gmail.com>
2007-01-18 20:42:40 GMT
I know this is not really a Perl question, Except that I use perl yo
generate the page.
I have a report that is displayed on a webpage in an 10 x 9 table
Originally we did it as one query per cell, then we combined it into one
monolithic query that returns one row with 72 columns
I am sure that there is some way to optimize this, maybe using sub-query,
which I have not been able to grasp yet.
so here is the beast:
my ($newdata, $noanswerdata, $timeddata, $misseddata, $highdata,
$normaldata, $lowdata, $monitordata);
# Open DB
my $dbh = DBI->connect( "dbi:$datasrc", "$sqluser", "$sqlpassword") ||
error("Unable to open user database: $DBI::errstr");
# Setup the Query
my $query = qq{SELECT
# New
sum(TO_DAYS(creationdate)<TO_DAYS(now() - INTERVAL 6 DAY) AND
status='O' AND date_format(lastcontact, "%Y")='0000' AND noanswer='0'),
sum(TO_DAYS(creationdate)=TO_DAYS(now() - INTERVAL 6 DAY) AND
status='O' AND date_format(lastcontact, "%Y")='0000' AND noanswer='0'),
sum(TO_DAYS(creationdate)=TO_DAYS(now() - INTERVAL 5 DAY) AND
status='O' AND date_format(lastcontact, "%Y")='0000' AND noanswer='0'),
sum(TO_DAYS(creationdate)=TO_DAYS(now() - INTERVAL 4 DAY) AND
(Continue reading)