This query takes over a minute to run. I realize that some of this is PHP code, but was hoping that someone could tell me how to speed this up (if possible).
Code:
$sql= "SELECT p.paymentmethod AS METHOD, SUM(amount * quantity) AS " .
"TOTAL, COUNT(DISTINCT(transactionid)) AS COUNT FROM tblTransactions t, " .
"tblPayments p WHERE t.reportid= " . $reportid . " AND t.transactionnum " .
"= p.transactionnum AND t.transdepartment = 'ROA' AND t.storeid = '" .
$storeid . "' AND t.registernum = '" . $registernum . "' GROUP BY " .
"p.paymentmethod ";
$rs = $db->query($sql,false);
while ($row = $db->fetch_array($rs))
{
extract($row);
$total_roa[$METHOD] = $TOTAL;
$count_roa[$METHOD] = $COUNT;
$line .= str_pad($METHOD . " ROA", 20," ", STR_PAD_RIGHT) . str_pad($COUNT,7," ",STR_PAD_LEFT) . "\n";
$line .= str_pad("$".$TOTAL,27," ", STR_PAD_LEFT) . "\n\n";
}
Thanks!