【发布时间】:2015-03-03 09:50:07
【问题描述】:
我的第一张桌子上有所有文章价格的演变,第一个日期定义了价格变化的日期。''evolution_price''
article -- date ----- unit.price
1 --- 2012-01-01 -- 1.20
1 --- 2013-01-01 -- 1.10
1 --- 2014-01-01 -- 1.20
2 --- 2012-01-01 -- 1.40
2 --- 2013-01-01 -- 1.50
2 --- 2014-01-01 -- 1.20
在我的第二张订单历史列表中(忘记单价 0.00)''orders''
article-- date---- price unit --- total order
1 ----- 2012-02-03 -- 0.00 -------- 12.10
2 ----- 2012-02-05 -- 0.00 -------- 15.20
1 ----- 2013-01-01 -- 0.00 -------- xxx
1 ----- 2014-05-05 -- 0.00
1 ----- 2014-05-06 -- 0.00
我正在寻找在第二张桌子上包含正确的单价,但在两个正确的日期之间是平等的。价格的演变可以是 20 日期/价格,价格必须介于 (date1 到 date2)price 和 (2date to 3日期)价格...等..;
第二个表需要''订单'':
1 ----- 2012-02-03 -- 1.20 ----- 12.10
2 ----- 2012-02-05 -- 1.20 ----- 15.20
1 ----- 2013-01-01 -- 1.10 ----- xxx
我测试了这个
update orders
set orders.unit_price =
(
select
unit_price
from evolution_price
where
orders.article_id = evolution_price.article_id
and
orders.order_date >= evolution_price.change_date
order
by evolution_price.change_date desc limit 1
);
【问题讨论】:
-
Turophile 的答案是我搜索的内容...我现在搜索如何使用 update 和 set 直接更新第二个表
标签: mysql