The core of the question is conditional aggregation, which I knew, but I fumbled a bit deciding between FILTER and CASE WHEN syntax.
Start by clarifying the table schema and event types, then write a query that aggregates daily counts per shop using conditional aggregation. Compute the visibility ratio as views divided by impressions, handling division by zero, and order the results by date and shop ID.
Pro tip: Mention that you'd validate the ratio by checking for anomalies like ratios >1, which could indicate data issues or multiple views per impression. Also, consider using NULLIF or CASE to avoid division by zero errors.
Identify the table structure, event types (impression, view), and relevant columns (shop_id, event_type, event_date). Confirm the granularity of the data.
Use conditional aggregation (e.g., SUM(CASE WHEN event_type = 'impression' THEN 1 ELSE 0 END)) to count impressions and views per shop per day.
Calculate views divided by impressions, using NULLIF or CASE to handle division by zero. Ensure the ratio is computed after aggregation.
Order by date and shop_id ascending. Select the date, shop_id, impressions, views, and visibility ratio as columns.
Check for edge cases (e.g., zero impressions, missing dates) and consider indexing or partitioning for performance if the table is large.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.