mysql将今日的数据更新到昨天去

mysql将今天的数据更新到昨天去

有这样一张表:t_abc

f_id gpid price f_day

2 2089 5.2 2012-07-09

50 2089 5.6 2012-07-10

102 2089 5.2 2012-07-11

203 2089 5.8 2012-07-12

就是让第二天的price写到前一天去。

我想得到的结果为:

f_id gpid price f_day

2 2089 5.6 2012-07-09

50 2089 5.2 2012-07-10

102 2089 5.8 2012-07-11

203 2089 null 2012-07-12

最后一天的price可以为null或者为0;

我是想不出来,请问下高手应该如何写sql语句????



SQL code

update t_abc a  left join t_abc b   on a.gpid=b.gpid and a.f_day=b.f_day-interval 1 Day
set a.price= b.price


SQL code
UPDATE t_abc a
SET a.price=b.price
LEFT JOIN t_abc b
ON a.gpid=b.gpid AND a.f_day=b.f_day-interval-1 day;


                        
    
    
                    
mysql将今日的数据更新到昨天去

相关文章:

你感兴趣的文章:

标签云: