我尝试在与其他值匹配时更新列中的特定值。
Database = wpddz_rg_lead_detail
如果与field_number 23值(蓝色圆圈)匹配,我需要在值列(field_number 21 =红色圆圈)中更新0(假设为5)。
field_number 23值(蓝色圆圈)的值是我可以传递给查询的变量
UPDATE wpddz_rg_lead_detail SET VALUE = 100 WHERE field_number = 21
做得对,但我需要首先检查我的变量= = de value from field_number 23
有没有人可以帮我解决问题?
编辑&溶液
Thx @Alex
UPDATE wpddz_rg_lead_detail AS a
JOIN wpddz_rg_lead_detail AS b
ON a.lead_id = b.lead_id
AND a.form_id = b.form_id
AND b.field_number = 23
AND b.value = '0e71f6d7abc70b41704faf98302a1d689a4cd80a'
SET a.value = a.value+100
WHERE a.form_id=2
AND a.field_number = 21
答案 0 :(得分:1)
UPDATE t t1
JOIN t t2
ON t1.lead_id=t2.lead_id
AND t1.form_id = t2.form_id
AND t2.field_number = 23
AND t2.value IS NOT NULL # here you can set whatever condition for 23 field
SET t1.`value`=5
WHERE
t1.lead_id=4
AND t1.form_id=2
AND t1.field_number=21