匹配2个SQL列if =,然后将另一个列更新1 [英] Match 2 sql columns if = then update a different column by 1
本文介绍了匹配2个SQL列if =,然后将另一个列更新1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找某人在一个表中提交的内容与数据库中另一个表之间是否存在匹配项. 我不太清楚如何设置它.我想要的是
Im looking to see if there is a match between what someone submitted in one table to a different table in the database. I can't quite figure out how to set it up. What im trying for is
IF tableA column A = tableB column B then table A column C = Column C + 1.
我尝试了更新方法,但这似乎对我不起作用.任何帮助将是巨大的.谢谢.
I have tried the update method but that seems to not be working for me. Any help would be great. Thanks.
推荐答案
通常是这样:
UPDATE TABLE_A a JOIN TABLE_B b
ON a.join_col = b.join_col AND a.column_a = b.column_b
SET a.column_c = a.column_c + 1
join_col
值很可能是user_id,因此您只能更新TABLE_A
中的行,其中相同用户在TABLE_B
中具有相同的值.
The join_col
value is likely the user_id so that you only update rows in TABLE_A
where that same user has the same value in TABLE_B
.
这篇关于匹配2个SQL列if =,然后将另一个列更新1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文