简体   繁体   中英

How to compare values between two columns with custom logic IF statement in MySQL

i have table like this, How do i compare this simple value with IF statement

i want to compare j_path column's value with j_foto's value based on their s_username, IF j_path's value and j_foto's value SAME, then the score column would be same, example in admin: is 8.

IF j_path's value and j_foto's value NOT THE SAME, then the score column would be j_foto. sorry for my beginner, appreciate your help. thanks

在此处输入图片说明

To be honest, your rules reduce to just using the value in j_foto :

update t
    set score = j_foto;

Conditional logic is not needed for what you describe.

You may have the situation where j_foto is NULL and in that case you might want j_path (although this situation is not mentioned in the question nor suggested by the data). In that case, use coalesce() :

update t
    set score = coalesce(j_foto, j_path);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM