SQS: Simple SQL Solutions (5 Solutions) ★★★★★
1. CASE expression\n\n\nUPDATE Salary SET sex = (CASE sex WHEN \'m\' THEN \'f\' ELSE \'m\' END)\n\n\n2. Ternary operator\n\n\nUPDATE Salary SET sex = IF(sex = \
**1. CASE expression**\n\n```\nUPDATE Salary SET sex = (CASE sex WHEN \'m\' THEN \'f\' ELSE \'m\' END)\n```\n\n**2. Ternary operator**\n\n```\nUPDATE Salary SET sex = IF(sex = \'m\', \'f\', \'m\')\n```\n\n**3. REPLACE() function**\n\n```\nUPDATE Salary SET sex = REPLACE(\'fm\', sex, \'\')\n```\n\n**4. Math approach**\n\n```\nUPDATE Salary SET sex = CHAR(ASCII(\'f\') + ASCII(\'m\') - ASCII(sex))\n```\n\n**5. XOR swap**\n\nhttps://en.wikipedia.org/wiki/XOR_swap_algorithm\n\n```\nUPDATE Salary SET sex = CHAR(ASCII(\'f\') ^ ASCII(\'m\') ^ ASCII(sex))\n```\n\nor\n\n```\nUPDATE Salary SET sex = CHAR(ASCII(sex) ^ 11)\n```\n\nNOTE: ```ASCII(\'f\') ^ ASCII(\'m\') = 11```\n\n
['MySQL']