Swap Two Gender Values
Problem statement
The people table contains one row per person with person_id and a gender value that is either male or female.
Return every row after swapping male to female and female to male. Return the columns person_id and gender, ordered by person_id ascending.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
people
| Column | Type | Nullable | Description |
|---|---|---|---|
| person_id | Integer | No | — |
| gender | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| person_id | Integer | No | — |
| gender | Text | No | — |
Row order: must match exactly. Numeric tolerance: 0.
Constraints
0 <= peoplerow count<= 100000.person_idis a unique non-null integer.genderis non-null and equals eithermaleorfemale.
Source note: The source image is a source-neutral excerpt of the author-reported prompt.