The core aggregation is straightforward enough: sum invalid and total observed per pixel, divide.
First, clarify the table schema and definitions of 'observed' vs 'missing' events and 'invalid' signal types. Then, write a SQL query that filters to yesterday's data, aggregates counts by pixel, and computes the invalid percentage using conditional aggregation, ensuring the denominator excludes missing events and handles zero observed events with a CASE statement or NULLIF.
Pro tip: Always confirm the definition of 'invalid' and 'missing' with the interviewer, as these terms can vary by context; also, explicitly state how you handle division by zero to avoid runtime errors.
Ask about the table structure, column names, and precise definitions of 'observed', 'missing', and 'invalid' events. Confirm that 'yesterday' refers to a specific date and that missing events should be excluded from the denominator.
Write a subquery or CTE to filter rows for yesterday's date and group by pixel. Use conditional aggregation (e.g., SUM(CASE WHEN signal_type = 'invalid' THEN event_count ELSE 0 END)) to count invalid events, and sum only observed events for the denominator.
Calculate the percentage as invalid_count * 100.0 / observed_count. Use NULLIF or a CASE statement to return 0 or NULL when observed_count is zero, depending on business preference.
Combine the steps into a single query, ensuring proper aliasing and formatting. Optionally, add a check for edge cases like pixels with no data.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.