首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

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

2012-08-08 
mysql将今天的数据更新到昨天去有这样一张表:t_abcf_idgpidpricef_day220895.22012-07-095020895.62012-07

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 Dayset a.price= b.price
[解决办法]
SQL code
UPDATE t_abc aSET a.price=b.priceLEFT JOIN t_abc bON a.gpid=b.gpid AND a.f_day=b.f_day-interval-1 day; 

热点排行