The core math is straightforward, a simple ratio of category duration to total duration.
Start by clarifying the schema and definitions (e.g., session time, reference date, category mapping). Then outline a SQL query that joins user activity with apps, filters to the last 7 days relative to the reference date, handles missing categories (e.g., using COALESCE to 'Unknown'), and computes the percentage of total session time per category. Finally, discuss edge cases and validation.
Pro tip: Mention that you would first check for data quality issues like null app_ids or negative session times, and consider using a LEFT JOIN to preserve all activity records even when app metadata is missing.
Ask about the table structures, definitions of session time, and how to handle missing categories. Confirm the reference date and the 7-day window.
Filter user activity to the last 7 days relative to the reference date, then sum session time per app_id.
Left join the aggregated activity with the apps table on app_id, and replace null categories with a placeholder like 'Unknown'.
Group by category, sum the session time, and divide by the total session time across all categories to get the percentage.
Check for anomalies, ensure percentages sum to 100%, and discuss how to handle apps with no activity or categories with zero time.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.