Back to problems

Calculate valid daily usage with gap constraints

SQL · ByteDance · Hard

The user_activity table records usage intervals in UTC. Its columns are user_id INT, start_ts TIMESTAMP, and end_ts TIMESTAMP. Valid rows have end_ts > start_ts; ignore any row that violates this condition. Write a Standard SQL query for the fixed UTC day 2025-11-15 that returns one row per user_id with that user's valid usage minutes as usage_minutes. Process each activity as follows: first clip it to the inclusive day window [2025-11-15 00:00:00, 2025-11-15 23:59:59]. Rows…

Checking your access…