I'm pulling several status over a specific time period and I'd like to pull another stat that would be "average sales per day" over this time period. I'm not sure how to do daily averages over a specific time period, can anyone provide some advice?
$whereSql = 'WHERE created >= '.$endTimestamp.' AND
created <= '.$startTimestamp;
$tru->query->run(array(
'name' => 'get-figures',
'sql' => 'SELECT
SUM(price) AS total_sales,
COUNT(id) AS total_orders,
AVG(total) AS order_total_average
(SELECT
SUM(quantity)
FROM `order_product`
INNER JOIN `order` ON (
`order`.id = order_product.order_id AND
`order`.created >= '.$endTimestamp.' AND
`order`.created <= '.$startTimestamp.' AND
`order`.type_id = '.$type->getId().'
)
) as total_units
FROM `order`
'.$whereSql.' AND type_id = '.$type->getId().'',
'connection' => 'store'
));