You are given a table Genders with the following structure:
| Column Name | Type |
|---|---|
| user_id | int |
| gender | varchar |
The user_id is the primary key for this table. The gender column contains values 'female', 'male', or 'other'. The table has an equal number of rows for each gender type.
Task: Rearrange the table so that rows alternate between 'female', 'other', and 'male' in that exact order. Within each gender group, the user_id values should be sorted in ascending order.
The final result should show the pattern: female, other, male, female, other, male, and so on.
Table Schema
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | Unique identifier for each user |
gender
|
varchar | Gender type: 'female', 'male', or 'other' |
Input & Output
| user_id | gender |
|---|---|
| 1 | male |
| 2 | other |
| 3 | female |
| 4 | female |
| 5 | other |
| 6 | male |
| user_id | gender |
|---|---|
| 3 | female |
| 2 | other |
| 1 | male |
| 4 | female |
| 5 | other |
| 6 | male |
The table is rearranged to alternate between female, other, and male. Within each gender group, users are ordered by user_id ascending. The first occurrence of each gender (user_id 3=female, 2=other, 1=male) comes first, followed by the second occurrence of each gender.
| user_id | gender |
|---|---|
| 1 | female |
| 2 | male |
| 3 | other |
| 4 | female |
| 5 | male |
| 6 | other |
| user_id | gender |
|---|---|
| 1 | female |
| 3 | other |
| 2 | male |
| 4 | female |
| 6 | other |
| 5 | male |
Even with sequential user IDs, the alternating pattern is maintained. Female users (1,4), other users (3,6), and male users (2,5) are arranged in the repeating pattern of female-other-male.
Constraints
-
1 ≤ user_id ≤ 1000 -
genderis one of'female','male', or'other' -
The table contains an equal number of
'female','male', and'other'rows