@newdev This is a great solution! The best thing is that I can use this technique in any problem involving switching, whether it's on a database or in code. Thanks a lot.
update salary set sex = CHAR(ASCII('f') ^ ASCII('m') ^ ASCII(sex));
@mclachlan ok，i agree with u， but why 11 can replace 'f' xor 'm'
Think of it as: 11 is the difference between 'm' and 'f'. (Like we said earlier, 11 = 'm' ^ 'f'.)
So now that we know the difference, it can be used to convert both an 'm' into an 'f' AND an 'f' into an 'm'.
f = 'm' ^ 11; // This converts an 'm' into an 'f'.
m = 'f' ^ 11; // This converts an 'f' into an 'm'.
@mclachlan @vivek_23 highly appreciate your help, thanks.
in ascii table, 'f' is
0x66, 'm' is
0x66 xor 0x6D =
0x0B, which is 11 in decimal
Another simple solution
update salary set sex= CHAR(ASCII('f') + ASCII('m') - ASCII(sex));
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.