PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Data Manipulation (SQL/Python)/Citi

Write SQL for 30-day activity and D7 retention

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's skill in SQL-based data manipulation and product-analytics competencies—specifically aggregation, deduplication to avoid double-counting, date arithmetic for time-windowed queries, cohort retention calculation, and percentage metrics—in the Data Manipulation (SQL/Python) domain.

  • easy
  • Citi
  • Data Manipulation (SQL/Python)
  • Data Scientist

Write SQL for 30-day activity and D7 retention

Company: Citi

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Technical Screen

You are given two tables. ### Table: `trades` - `user_id` (BIGINT) - `trade_time` (TIMESTAMP) — timestamp of the trade - `volume` (NUMERIC) - `asset` (TEXT) ### Table: `users` - `user_id` (BIGINT, PK) - `signup_date` (DATE) Assumptions: - `trade_time` is stored in UTC. - “Last 30 days” is relative to `CURRENT_DATE` (or `CURRENT_TIMESTAMP`) in UTC. - When counting users, avoid double-counting a user who has multiple trades. --- ## Question 1 — 30-day trading intensity Compute the **percentage of active traders** in the last 30 days who made **at least 3 trades** in the last 30 days. - Define the denominator as: users with **≥ 1** trade in the last 30 days. **Required output (single row):** - `active_users_30d` - `users_with_3plus_trades_30d` - `pct_users_with_3plus_trades_30d` --- ## Question 2 — 7-day retention (trading-based) Compute **D7 retention by signup cohort** where a user is considered **retained on D7** if they made **≥ 1 trade exactly on calendar day `signup_date + 7`**. - Only include cohorts where `signup_date <= CURRENT_DATE - 7` (so D7 is observable). **Required output (one row per `signup_date`):** - `signup_date` - `cohort_size` - `retained_users_d7` - `d7_retention_rate`

Quick Answer: This question evaluates a candidate's skill in SQL-based data manipulation and product-analytics competencies—specifically aggregation, deduplication to avoid double-counting, date arithmetic for time-windowed queries, cohort retention calculation, and percentage metrics—in the Data Manipulation (SQL/Python) domain.

Related Interview Questions

  • Compute 30-day power users and 7-day retention - Citi (medium)
Citi logo
Citi
Feb 6, 2025, 12:00 AM
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
6
0

You are given two tables.

Table: trades

  • user_id (BIGINT)
  • trade_time (TIMESTAMP) — timestamp of the trade
  • volume (NUMERIC)
  • asset (TEXT)

Table: users

  • user_id (BIGINT, PK)
  • signup_date (DATE)

Assumptions:

  • trade_time is stored in UTC.
  • “Last 30 days” is relative to CURRENT_DATE (or CURRENT_TIMESTAMP ) in UTC.
  • When counting users, avoid double-counting a user who has multiple trades.

Question 1 — 30-day trading intensity

Compute the percentage of active traders in the last 30 days who made at least 3 trades in the last 30 days.

  • Define the denominator as: users with ≥ 1 trade in the last 30 days.

Required output (single row):

  • active_users_30d
  • users_with_3plus_trades_30d
  • pct_users_with_3plus_trades_30d

Question 2 — 7-day retention (trading-based)

Compute D7 retention by signup cohort where a user is considered retained on D7 if they made ≥ 1 trade exactly on calendar day signup_date + 7.

  • Only include cohorts where signup_date <= CURRENT_DATE - 7 (so D7 is observable).

Required output (one row per signup_date):

  • signup_date
  • cohort_size
  • retained_users_d7
  • d7_retention_rate

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More Citi•More Data Scientist•Citi Data Scientist•Citi Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.