This question evaluates the ability to perform time-windowed aggregations, cumulative transaction summation, cross-table joins, and click-through-rate (CTR) calculations using SQL or Python, with attention to timestamp handling and event filtering.
You are given three tables (timezone: UTC). Assume create_date, transaction_time, and event_time are timestamps.
usersuser_id
BIGINT PRIMARY KEY
create_date
TIMESTAMP -- account creation time
transactionstransaction_id
BIGINT PRIMARY KEY
user_id
BIGINT NOT NULL REFERENCES
users(user_id)
transaction_time
TIMESTAMP NOT NULL
product
VARCHAR NOT NULL -- e.g.,
'crypto'
,
'card'
, etc.
amount_gbp
NUMERIC(18,2) NOT NULL
status
VARCHAR NOT NULL --
'completed'
or
'declined'
activityuser_id
BIGINT NOT NULL REFERENCES
users(user_id)
event_time
TIMESTAMP NOT NULL
product
VARCHAR NOT NULL
event_type
VARCHAR NOT NULL --
'view'
or
'click'
Return all users whose cumulative amount_gbp from completed transactions with product = 'crypto' is strictly greater than 100 within the window:
users.create_date
(inclusive)
users.create_date + INTERVAL '7 days'
(exclusive)
Output columns:
user_id
crypto_amount_7d_gbp
Using the activity table, compute per-product:
views = count(*) where event_type = 'view'
clicks = count(*) where event_type = 'click'
ctr = clicks / views
Return the product with the highest CTR.
Output columns:
product
ctr
Notes:
views = 0
(e.g., exclude them).