根据电话号码的重复更新列

时间:2017-03-29 13:34:54

标签: mysql

我有一张表格,其中我有以下数据:

phone_num repeat_next date
12345          -1   2017-01-01(initially repeat_next values will be -1 default )
12345          -1   2017-01-02(if the same phone number exists in other day then by output should be as below)

phone_num repeat_next  date
12345          1      2017-01-01 (which is max date of phone repeat number minus latest date )
12345         -1     2017-01-02

在这种情况下,我的repeat_next值应该如上所述更新((2017-01-02) - (2017-01-01))

所以我需要根据下一个出现日期进行更新

例如,如果同一个电话号码再次出现:

phone_num  repeat_next    date
12345           1      2017-01-01
12345          -1      2017-01-02
12345          -1      2017-01-08 

然后在那种情况下输出应该如下

phone_num repeat_next date
12345          1      2017-01-01
12345          6      2017-01-02
12345         -1     2017-01-08 

在这种情况下是(2017-01-08) - (2017-01-02) 提前致谢

0 个答案:

没有答案