Pretty applied question, not a brain teaser.
Start by clarifying the table schema and the definition of 'past 7 days' (e.g., relative to current date or max date in data). Then write a SQL query that filters events to the last 7 days, groups by shop and calendar day, and counts distinct user IDs. Use date functions to extract the day from the timestamp and ensure proper handling of time zones if needed.
Pro tip: Mention that you would check for data quality issues like duplicate events or missing user IDs, and consider using a subquery or CTE to filter dates first for better performance. Also, clarify whether 'unique users' means distinct users per shop per day or overall unique users across all shops per day.
Ask about the table name, column names, data types, and time zone. Confirm the definition of 'past 7 days' and whether it includes today.
Use a WHERE clause with a date function to restrict events to the last 7 days relative to the current date or the maximum date in the table.
Extract the date part from the timestamp and group by shop_id and date. Use COUNT(DISTINCT user_id) to count unique users per group.
Consider time zones, missing dates (shops with zero views), and performance. Use CTEs or subqueries to filter early and avoid scanning the entire table.
Present the SQL query clearly, explaining each part. Optionally, discuss how you would validate the results or handle large-scale data.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.