假设order
表:user_id, order_id, created (timestamp)
,...
如何计算一个用户的后续订单之间的平均时间间隔? (用户创建订单的频率如何?)
答案 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