填补日期和阶段之间的差距以获得机会

时间:2016-12-29 10:17:21

标签: mysql date cross-join

我对MySQL很陌生,想要求帮助,非常感谢!

让我们像opp_history表一样(加上它的pk):

opp_id date_created stage                   
00658000009Pa0gAAC  2016-11-05  Qualification
00658000009Pa0gAAC  2016-11-06  Validating benefits
00658000009Pa0gAAC  2016-11-09  Offer
00658000009Pa0gAAC  2016-11-09  Validating benefits
00658000009Pa0gAAC  2016-11-10  Offer
00658000009Pa0gAAC  2016-11-15  Closed Lost
00658000009PIZHAA4  2016-11-04  Validating benefits
00658000009PIZHAA4  2016-11-04  Offer
00658000009PIZHAA4  2016-11-04  Qualification
00658000009PIZHAA4  2016-11-04  Offer
00658000009PIZHAA4  2016-11-10  Closed Lost

我想做的是填补每个阶段与前一阶段值之间的日期差距,所以:

opp_id date_created stage                   
00658000009Pa0gAAC  2016-11-05  Qualification
00658000009Pa0gAAC  2016-11-06  Validating benefits
00658000009Pa0gAAC  2016-11-07  Validating benefits
00658000009Pa0gAAC  2016-11-08  Validating benefits
00658000009Pa0gAAC  2016-11-09  Offer
00658000009Pa0gAAC  2016-11-09  Validating benefits
00658000009Pa0gAAC  2016-11-10  Offer
00658000009Pa0gAAC  2016-11-11  Offer
00658000009Pa0gAAC  2016-11-12  Offer
00658000009Pa0gAAC  2016-11-13  Offer
00658000009Pa0gAAC  2016-11-14  Offer
00658000009Pa0gAAC  2016-11-15  Closed Lost
00658000009PIZHAA4  2016-11-04  Validating benefits
00658000009PIZHAA4  2016-11-04  Offer
00658000009PIZHAA4  2016-11-04  Qualification
00658000009PIZHAA4  2016-11-05  Offer
00658000009PIZHAA4  2016-11-06  Offer
00658000009PIZHAA4  2016-11-07  Offer
00658000009PIZHAA4  2016-11-08  Offer
00658000009PIZHAA4  2016-11-09  Offer
00658000009PIZHAA4  2016-11-10  Closed Lost

但即使我读过这篇文章:MySQL Fill in missing dates between two dates for a given status 我仍然在努力应用相同的逻辑导致opp_id,其中最大日期必须是每个opp_id的最大创建日期。

我已按照那里的建议创建了日历虚拟表和视图。

非常感谢您的建议! 随意问什么,Z。

0 个答案:

没有答案