Click here to see the full article post
How about this one?
update salary as a
join salary as b on a.sex != b.sex
set a.sex = b.sex;
Also, we can do with the following query:
update salary set sex = IF(sex = 'm', 'f', 'm')
@Himanshu that's correct. 👍
@rfvbnju Looks very interesting!
Hah, I ended up using something over-complicated, with ELT and FIELD.
But before that I tried this, which is also a bit silly but which worked with the testcase and failed upon submission (4/8 test cases passed). I don't know why it failed, though, perhaps some sql_mode?
update salary sf, salary sm set sf.sex = 'm', sm.sex = 'f' where sf.sex = 'f' and sm.sex = 'm';
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.