Your question is Token Consumption Moving Averages. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Anthropic needs a daily view of token consumption for enterprise accounts using the Claude API. Write a PostgreSQL query that aggregates usage events and calculates both short-term usage trends and cumulative consumption.
account_type = 'enterprise' and status = 'active'.daily_tokens. Treat NULL token counts as zero.| Column | Type | Description |
|---|---|---|
| account_idPK | INTEGER | Unique enterprise account identifier |
| account_name | VARCHAR(100) | Enterprise customer name |
| account_type | VARCHAR(30) | Customer segment |
| status | VARCHAR(20) | Account lifecycle status |
| Column | Type | Description |
|---|---|---|
| usage_idPK | BIGINT | Unique token usage event identifier |
| account_id | INTEGER | References enterprise_accounts.account_id |
| usage_date | DATE | UTC calendar date of token usage |
| token_count | BIGINT | Tokens consumed in the event |