开发者

Mysql Update with if statement

开发者 https://www.devze.com 2023-02-21 21:07 出处:网络
In MySQL Table1 columns Id, Foo, Bar, Choc, Blk, AB Table2 columns ID, A, B, C Im trying to update table 1 col AB with result of

In MySQL

Table1 columns Id, Foo, Bar, Choc, Blk, AB

Table2 columns ID, A, B, C 

Im trying to update table 1 col AB with result of

IF( (C / ((A + B)/ 2))>1, "A...", "B..." ) from Table2 

Where T1.i开发者_开发知识库d =t2.id


UPDATE table1
JOIN Table2 on Table1.id = Table2.id
SET AB = CASE WHEN C / ((A + B)/ 2) > 1 THEN "A..." ELSE "B..." END
0

精彩评论

暂无评论...
验证码 换一张
取 消