如果条件满足,则更新表.(将表b中的值更新为a)需要对应的值 [英] Update table if conditions met. (update the value from table b to a) corresponding value required
本文介绍了如果条件满足,则更新表.(将表b中的值更新为a)需要对应的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表 a,其中包含字段日期"、时间"、成本和 order_id
I have a table a in which i have fields 'date', 'time', cost and order_id
表 b 包含字段 'year' 'month' 'hour' 'cost' 和 order_id 字段.
table b which has fields 'year' 'month' 'hour' 'cost' and order_id fields.
两个表都与order_id"字段相关联.如果两个表中的年、月、小时和 order_id 相同,我想更新表 a,并将表 b 中的相应值更新到表 a 字段成本"
both tables are linked with "order_id" field. i want to update table a if year, month, hour and order_id is same in both tables and update the corresponding value from table b to table a field "cost"
我用过这个语句,但是查询不起作用?它有什么问题?我需要帮助
I have used this statement, but query is not working? what is wrong in it? i need help
UPDATE item a, cost b
SET a.cost = b.cost
WHERE a.order_id = b.order_id
AND YEAR(a.date) = b.YEAR
AND month(a.date) = b.month
AND hour(a.time) = b.hour
推荐答案
UPDATE item a
JOIN cost b ON a.order_id = b.order_id
AND YEAR(a.date) = b.YEAR
AND month(a.date) = b.month
AND hour(a.time) = b.hour
SET a.cost = b.cost
这篇关于如果条件满足,则更新表.(将表b中的值更新为a)需要对应的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文