bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 627. Swap Salary

627. Swap Salary

Leetcode Solutions

Swapping Gender Values in the Salary Table

  1. Begin with the UPDATE statement to indicate that we are modifying the Salary table.
  2. Use the SET clause to specify the column we are updating, which is the sex column.
  3. Inside the SET clause, use a CASE statement to evaluate the current value of the sex column.
  4. For each row, check the value of sex using the WHEN clause.
  5. If the value is 'm', then use THEN to set it to 'f'.
  6. If the value is not 'm', it must be 'f', so use ELSE to set it to 'm'.
  7. End the CASE statement with END to complete the conditional logic.
  8. Execute the query to update the table with the swapped values.
erDiagram
    Salary {
        int id PK
        varchar name
        ENUM sex
        int salary
    }

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...