Daily Credits Consumed by Subscription Tier

Last updated: November 29, 2026

Quick Overview

Using a generations table (user_id, created_at, credits_used, status) and a subscriptions table (user_id, plan, started_at, ended_at), write SQL that returns daily credits consumed by successful generations, broken out by the plan the user was on at generation time.

Suno
Data Manipulation (SQL/Python)
Data Scientist
Suno
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Using a generations table (user_id, created_at, credits_used, status) and a subscriptions table (user_id, plan, started_at, ended_at), write SQL that returns daily credits consumed by successful generations, broken out by the plan the user was on at generation time.

A SQL screen in the style of Suno's data team, where credits are the unit of both pricing and GPU cost. The interviewer wants a correct point-in-time join to the subscription history and sensible handling of free users and failed generations.

What the Interviewer Expects
  • Join subscriptions on a time range, not just user_id
  • Treat users with no active subscription as Free
  • Filter out failed or refunded generations
  • Group by calendar day in a stated time zone
  • Explain how overlapping subscription rows would double count
Key Topics to Cover
Point-in-time joins
LEFT JOIN and COALESCE
Date bucketing
Data quality checks
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you compute credits per active user per tier?
  • How do you detect users whose subscription rows overlap?
  • How would you attribute credits when a user upgrades mid-day?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Assume generations.status is one of succeeded, failed, refunded and only succeeded rows consume credits. subscriptions.ended_at is NULL while active, and the interval is half-open `[started_...

Approach

Filter generations to successful ones, LEFT JOIN subscriptions where the generation time falls inside the subscription interval, coalesce a missing plan to free, then group by day and plan....


Submit Your Answer
Markdown supported

Related Questions