我想在我的数据库中更新字段。我有两个表和表字段如下
表 operations_per_assembly
字段 operation_id,is_mecahnical
operations
字段 id,repair_type_id
现在我想更新is_mechanical
字段,其中repair_type_id
= 3
UPDATE
`operations_per_assembly`
JOIN `operations`
ON `operations`.`id` = `operations_per_assembly`.`operation_id`
SET `operations_per_assembly`.`is_mechanical` = '4'
WHERE `operations_per_assembly`.`operation_id` = `operations`.`id`
AND `operations_per_assembly`.repair_type_id = 3
请帮帮我。
将repair_type_id = 3条件放入连接条件中。通过这种方式,您将告知仅在repair_type_id = 3时加入,因此您将只获得这些记录。
UPDATE
`operations_per_assembly`
JOIN `operations`
ON `operations`.`id` = `operations_per_assembly`.`operation_id` AND `operations`.repair_type_id = 3
SET `operations_per_assembly`.`is_mechanical` = '4'
UPDATE `operations_per_assembly` a
JOIN `operations` b
ON a.operation_id = b.id
SET a.is_mechanical = '4'
WHERE codition (user proper condition)
在WHERE
子句中,您正在使用operations_per_assembly
。repair_type_id
,但你的operations_per_assembly
表中没有repair_type_id
。
那么试试下面的查询:
UPDATE `operations_per_assembly` PAS
JOIN `operations` OPE ON OPE.`id` = PAS.`operation_id`
SET PAS.`is_mechanical` = '4'
WHERE OPE.repair_type_id = 3