This question evaluates a data scientist's ability to perform SQL-level user- and account-level aggregation, grouping, and NULL-aware filtering to compute counts and proportions across related tables in the Data Manipulation (SQL/Python) domain.
You are analyzing a product in which a single user can own multiple accounts.
Use the following tables:
accounts
account_id
BIGINT — unique account ID
user_id
BIGINT — owner of the account
created_at
TIMESTAMP — when the account was created
last_visit_at
TIMESTAMP — most recent time the user visited that account
notifications
notification_id
BIGINT — unique notification ID
account_id
BIGINT — account that received the notification
sent_at
TIMESTAMP — when the notification was sent
read_at
TIMESTAMP NULL — when the notification was read;
NULL
means unread
Assumptions:
Write SQL for the following:
accounts
table, return the number of users who have exactly 2 accounts, exactly 3 accounts, and 4 or more accounts.
account_bucket
(
'2'
,
'3'
, or
'4+'
)
user_count
read_at IS NULL
.
pct_multi_account_users_with_unread_notifications
as a decimal between 0 and 1.