Break the problem into stages: first deduplicate clicks to the earliest per ad request, then aggregate daily metrics per campaign, and finally compute the 7-day windowed totals, CTR, RPM, and standard deviation of daily RPM. Use window functions to handle the rolling window and apply the filters and ordering at the end.
Pro tip: Clarify the definition of RPM (revenue per mille) and confirm whether it's based on charged clicks or impressions; also mention that deduplication should happen before any aggregation to avoid double-counting revenue.
Use a window function like ROW_NUMBER() partitioned by ad_request_id and ordered by click_timestamp to select only the earliest click per ad request.
Join impressions and deduplicated clicks, then group by campaign_id and date to compute daily impressions, charged clicks, and revenue (if available).
Use window functions with a 7-day range to sum impressions and clicks, and calculate CTR and RPM for each campaign over the window.
Within the 7-day window, compute the standard deviation of daily RPM using STDDEV or equivalent, ensuring it's calculated over the daily values.
Apply the HAVING clause to keep campaigns with total impressions >= 10000, then order by RPM descending and standard deviation ascending.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.