0
daily_average
列總是返回零。默認時間戳值是過去一週。想知道我在做什麼錯在每天獲得平均訂單價值?幫助計算平均每天
SELECT
SUM(price+shipping_price) AS total_sales,
COUNT(id) AS total_orders,
AVG(price+shipping_price) AS order_total_average,
(SELECT
SUM(quantity)
FROM `order_product`
INNER JOIN `order` ON (
`order`.id = order_product.order_id AND
`order`.created >= '.$startTimestamp.' AND
`order`.created <= '.$endTimestamp.' AND
`order`.type_id = '.$type->getId().' AND
`order`.fraud = 0
)
) as total_units,
SUM(price+shipping_price)/DATEDIFF('.$endTimestamp.', '.$startTimestamp.') as daily_average
FROM `order`
WHERE created >= '.$startTimestamp.' AND
created <= '.$endTimestamp.' AND
fraud = 0 AND
type_id = '.$type->getId().'
什麼是startTimestamp和endTimestamp?時代以來的時間?格式化日期?如果格式化,如何? DATEDIFF需要日期而不是時間戳。如果從時代開始,FROM_UNIXTIME會有所幫助。 – justkt 2011-02-25 15:04:05
你明白了嗎? – Rudu 2011-02-25 17:57:29