I got the basic structure down pretty fast, CASE WHEN visible = true THEN 1 ELSE 0 END divided by count, grouped by shop and date.
First, aggregate the raw visibility records to compute each shop's daily visibility rate by dividing the sum of visible flags by the total views per shop per day. Then, use a window function to calculate a 7-day rolling average of these daily rates and filter for shops where that average is below 50%.
Pro tip: Clarify whether the 7-day window should be based on calendar days or the last 7 days of data, and explicitly state your assumption about handling missing days (e.g., treating them as zero visibility or excluding them).
Group the raw records by shop ID and view date, then compute the daily visibility rate as SUM(visible)/COUNT(*) or AVG(visible).
Use a window function (e.g., AVG() OVER (PARTITION BY shop_id ORDER BY view_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)) to calculate the rolling average of daily rates over the past 7 days.
Select shops where the 7-day rolling average is less than 0.5, ensuring you consider the most recent date or all dates as needed.
Address missing dates, partial data, and ensure the window includes only the last 7 days (not 7 rows if dates are missing). Validate results with a small sample.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.