Given two tables Friends and Activities, find the names of all activities with neither the maximum nor the minimum number of participants.
Each activity in the Activities table is performed by any person in the Friends table. Return the result in any order.
- Count participants for each activity
- Exclude activities with maximum participant count
- Exclude activities with minimum participant count
- Return the middle-range activities
Table Schema
| Column Name | Type | Description |
|---|---|---|
id
PK
|
int | Primary key - friend identifier |
name
|
varchar | Name of the friend |
activity
|
varchar | Name of activity the friend participates in |
| Column Name | Type | Description |
|---|---|---|
id
PK
|
int | Primary key - activity identifier |
name
|
varchar | Name of the activity |
Input & Output
| id | name | activity |
|---|---|---|
| 1 | Alice | Travel |
| 2 | Bob | Travel |
| 3 | Charlie | Dancing |
| 4 | David | Singing |
| 5 | Eve | Singing |
| 6 | Frank | Singing |
| id | name |
|---|---|
| 1 | Travel |
| 2 | Dancing |
| 3 | Singing |
| name |
|---|
Travel has 2 participants, Dancing has 1 participant, and Singing has 3 participants. Since Dancing has the minimum (1) and Singing has the maximum (3), only Travel would qualify. However, Travel also ties for minimum with Dancing, so no activities remain after filtering.
| id | name | activity |
|---|---|---|
| 1 | Alice | Travel |
| 2 | Bob | Dancing |
| 3 | Charlie | Dancing |
| 4 | David | Singing |
| 5 | Eve | Singing |
| 6 | Frank | Singing |
| 7 | Grace | Reading |
| 8 | Henry | Reading |
| id | name |
|---|---|
| 1 | Travel |
| 2 | Dancing |
| 3 | Singing |
| 4 | Reading |
| name |
|---|
| Dancing |
| Reading |
Travel has 1 participant (minimum), Singing has 3 participants (maximum), while Dancing and Reading each have 2 participants. Since 2 is neither the minimum (1) nor maximum (3), both Dancing and Reading are returned.
Constraints
-
1 ≤ Friends.id ≤ 1000 -
1 ≤ Activities.id ≤ 1000 -
Friends.nameandActivities.namecontain only English letters - Each activity in Activities table appears at least once in Friends table