SQL interview question: Days Between Two Dates
Calculate Account Age in Days
The retention team wants to segment users by how long they've been subscribers.
Calculate the number of days since each user's subscription_start date (as of January 1, 2026).
Return user_id, username, and days_subscribed as a whole number of days. Order by days subscribed descending.
Skills: date arithmetic with JULIANDAY
Tables
subscriptions 5 rows
- user_id integer PK
- username text
- subscription_start text
| user_id | username | subscription_start |
|---|---|---|
| 1 | alice_tech | 2024-01-15 |
| 2 | bob_dev | 2024-06-20 |
| 3 | carol_data | 2024-11-10 |