I knew I needed a join and a group by date, but I fumbled the aggregation syntax for a minute.
Start by clarifying the table schemas and the definition of 'harmful' (e.g., flag = 1). Then, join the views and videos tables on video_id, group by date, and compute the percentage as the sum of views on harmful videos divided by total views, multiplied by 100. Use a LEFT JOIN to ensure all views are counted, and handle NULLs appropriately.
Pro tip: Always clarify edge cases: What if a video has no flag? Should it be considered non-harmful? Also, consider time zones for daily aggregation—Meta often uses UTC. Mentioning these shows attention to detail.
Ask about the table structures: views (view_id, video_id, timestamp) and videos (video_id, harmful_flag). Confirm the definition of 'harmful' and how to handle missing flags.
Use a LEFT JOIN to combine views with video metadata, ensuring all views are included. Treat NULL harmful_flag as non-harmful (0).
Group by date (using DATE(timestamp)) and calculate total views and harmful views (SUM(CASE WHEN harmful_flag = 1 THEN 1 ELSE 0 END)).
Calculate the percentage as (harmful_views * 100.0 / total_views), ensuring floating-point division to avoid integer truncation.
Consider days with zero views (avoid division by zero), and if needed, filter out days with no views. Also, discuss indexing on date and video_id for performance.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.