如何计算订单之间的平均时间间隔

时间:2013-06-17 11:00:32

标签: mysql

假设order表:user_id, order_id, created (timestamp),...

如何计算一个用户的后续订单之间的平均时间间隔? (用户创建订单的频率如何?)

1 个答案:

答案 0 :(得分:1)

select case when count(order_id) = 0
       then -1
       else (max(created) - min(created)) / count(order_id)
       end as avg_order_time
from `order`
where user_id = 123