我在表格中有一堆条目,如下所示
|id | agency_id|old_status|new_statusts|timestamp |contact_id|alter_type |last_mod_by|
------------------------------------------------------------------------------------------------
|968 |4926185635| Verified| Verified |2016-11-2210:46:56| 969|LeadAdded | 1|
|4274|4926185635| Verified| Verified |2017-01-1410:46:56| 969|NoteAdded | 1|
|4275|4926185635| Verified| Quoted |2017-01-2110:46:56| 969|StatusChange| 1|
我想做的是获取从添加时间到验证时间以及验证到引用时间的累积平均时间。
我浏览了本网站上的不同条目,似乎找不到合适的内容。
实际上发生的事情是在添加潜在客户(行 ID 968)时放入一个条目,然后在潜在客户状态从已添加更改为已验证(行 ID 4275)时添加另一个条目,其中有大量具有独特性的条目值为 contact_id 和 agency_id
我想获得从 Lead Added 到 Verified 的所有条目的平均值
非常感谢任何帮助
最佳答案
如果我理解正确,您希望将 leadAdded
和 statusChange
之间的区别设置为“Quoted”。这表明条件聚合或连接:
select avg(datediff(tq.ts, tv.ts)) as avg_time_to_quote
from t tv join
t tq
on tv.agency_id = tq.agency_id and
tv.alter_type = 'LeadAdded' and
tq.alter_type = 'StatusChange' and
tq.new_status = 'Quoted';
关于mysql - 计算同一个表mysql中条目的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42509710/