Count user signups per country for the first quarter of 2024

Quick Overview

Write a PostgreSQL query that joins users to countries and counts how many users signed up in each country during the first quarter of 2024. It tests inner joins, inclusive date-range filtering, grouping on a key, and a tie-breaker that makes the sort order deterministic.

Count user signups per country for the first quarter of 2024

Company: Dropbox

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

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. ```hint Date boundaries Both 2024-01-01 and 2024-03-31 count. Choose a range test that keeps both ends and would still be right if `signup_date` were a timestamp. ```

Overview: Write a PostgreSQL query that joins users to countries and counts how many users signed up in each country during the first quarter of 2024. It tests inner joins, inclusive date-range filtering, grouping on a key, and a tie-breaker that makes the sort order deterministic.

Dropbox logo
Dropbox
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

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

ColumnTypeMeaning
country_idINTUnique id of the country
country_nameVARCHAR(100)Name of the country (NOT NULL)

Primary key: country_id.

users

ColumnTypeMeaning
user_idINTUnique id of the user
usernameVARCHAR(100)The user's name (NOT NULL)
country_idINTCountry of the user, references countries.country_id
signup_dateDATEDate 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_idcountry_name
1Brazil
2Canada
3France
4Japan

users

user_idusernamecountry_idsignup_date
101ana12024-01-15
102bruno12024-03-31
103carla12024-04-01
104dave22023-12-31
105emma22024-02-29
106felix32024-01-01
107gina32024-03-10
108hiro42024-05-20

Expected result:

country_namesignup_count
Brazil2
France2
Canada1

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.