Is it possible to get total SUM of two columns? After the query is executed I'm displaying the results in a while loop. It seems that this won't be possible since I'm matching the data against matching id's.
<?php
$query = "SELECT c.company_id, c.company_name, ifnull(t.skuCount, 0) AS skuCount, ifnull(t.productSum, 0) AS productSum
FROM company c
LEFT JOIN (SELECT products_coid, COUNT(*) AS skuCount, SUM(products_inventory * products_wesell) AS productSum FROM products GROUP BY products_coid) t
ON c.company_id = t.products_coid";
$result = mysql_query($query);
?>
<?php
while($row = mysql_fetch_assoc($result)) {
extract($row);
?>
<tr>
<td><?php echo $company_name; ?></td>
<td><?php echo $skuCount; ?></td>
<td><?php echo $productSum; ?></td>
</tr>
<?
}
?>
However, I want to include the grand totals in the <tfoot> of the table. Would it be better to do this in php or let mySQL do the calculation? The <tfoot> is above and outside the while loop.
Your help is appreciated. Thanks.