Count how many users signed up in each country with a signup_date from 2024-01-01 to 2024-03-31 inclusive. Return each country's name and its signup count, listing only countries with at least one signup in that range.
Input Table(s)
countries
| Column | Type | Meaning |
|---|
| country_id | INT | Unique id of the country |
| country_name | VARCHAR(100) | Name of the country (NOT NULL) |
Primary key: country_id.
users
| Column | Type | Meaning |
|---|
| user_id | INT | Unique id of the user |
| username | VARCHAR(100) | The user's name (NOT NULL) |
| country_id | INT | Country of the user, references countries.country_id |
| signup_date | DATE | Date the user signed up (NOT NULL) |
Primary key: user_id. Foreign key: users.country_id references countries.country_id.
Output Contract
-
Columns, in this order:
country_name
,
signup_count
.
-
signup_count
is an integer: the number of users in that country whose
signup_date
is between 2024-01-01 and 2024-03-31, both ends included.
-
One row per country with
signup_count
of at least 1.
-
Order by
signup_count
descending, then
country_name
ascending.
-
No rounding is needed.
Example
countries
| country_id | country_name |
|---|
| 1 | Brazil |
| 2 | Canada |
| 3 | France |
| 4 | Japan |
users
| user_id | username | country_id | signup_date |
|---|
| 101 | ana | 1 | 2024-01-15 |
| 102 | bruno | 1 | 2024-03-31 |
| 103 | carla | 1 | 2024-04-01 |
| 104 | dave | 2 | 2023-12-31 |
| 105 | emma | 2 | 2024-02-29 |
| 106 | felix | 3 | 2024-01-01 |
| 107 | gina | 3 | 2024-03-10 |
| 108 | hiro | 4 | 2024-05-20 |
Expected result:
| country_name | signup_count |
|---|
| Brazil | 2 |
| France | 2 |
| Canada | 1 |
Brazil counts ana and bruno (2024-03-31 is the last day and is included) but not carla, who signed up on 2024-04-01. France counts felix (2024-01-01, the first day) and gina. Canada counts only emma. Japan has no signup in range, so it does not appear. Brazil and France tie at 2 and are ordered by name.
Constraints and Clarifications
-
users
has at most 10,000 rows and
countries
has at most 200 rows.
-
Each
user_id
is unique, so each row is one signup.
-
Every
country_id
in
users
exists in
countries
. A user row with a NULL
country_id
belongs to no country and is not counted.
-
Countries with no signups in the range are left out; do not return them with a count of 0.
-
If two countries share a name, they are still separate countries and get separate rows.