如果条件满足,更新 table。 (将tableb的值更新为a)需要相应的值
Update table if conditions met. (update the value from table b to a) corresponding value required
我有一个 table a,其中有字段 'date'、'time'、成本和 order_id
table b 具有字段 'year' 'month' 'hour' 'cost' 和 order_id 字段。
两个 table 都与 "order_id" 字段链接。我想更新 table a 如果年、月、小时和 order_id 在两个 table 中都相同并将相应的值从 table b 更新为 table一个字段 "cost"
我用过这个语句,但是查询不起作用?它有什么问题?我需要帮助
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
我有一个 table a,其中有字段 'date'、'time'、成本和 order_id
table b 具有字段 'year' 'month' 'hour' 'cost' 和 order_id 字段。
两个 table 都与 "order_id" 字段链接。我想更新 table a 如果年、月、小时和 order_id 在两个 table 中都相同并将相应的值从 table b 更新为 table一个字段 "cost"
我用过这个语句,但是查询不起作用?它有什么问题?我需要帮助
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