SQL Playground Mission: Pageview Deduplication Audit
Compare row counts with distinct session counts so repeated pageviews don't masquerade as unique reach.
Raw event rows and unique reach are different metrics. A page can have 26 pageview rows while fewer sessions actually saw it, because some sessions viewed the same path more than once.
This audit makes the difference visible. For each path, compare total pageviews with distinct sessions, then keep only paths where repeated views exist.
select entity_key,
count(*) as raw_rows,
count(distinct user_or_session_id) as unique_entities,
count(*) - count(distinct user_or_session_id) as repeat_rows
from event_table
group by entity_key
having count(*) > count(distinct user_or_session_id) Preparing for an interview? The deduplication interview questions cover audits and keeper rows, with model answers to compare against.
Schema · Website Analytics Table · pageviews 4 columns · 75 rows
One row per page viewed within a session, in view_order.
For each path with repeated pageviews, return path, pageviews, distinct sessions, and repeat_views. Sort by repeat_views descending, then path.
Run your query to inspect the result.
Expected answer
- Columns: path, pageviews, sessions, repeat_views.
- Rows: only paths where pageviews exceed distinct sessions.
- The homepage has 26 pageviews from 22 sessions, so it has 4 repeat views.
Related
Nested SELECTs, IN, EXISTS, and correlation.
Ranking, LAG/LEAD, and running totals at a glance.
Practice ranking, running totals, and top row per group.
The default RANGE frame groups tied rows; use ROWS.
Filter window results in a CTE or with QUALIFY.
The WITH clause, chained steps, and CTE vs subquery.