The FULL OUTER JOIN part is what tripped me up at first.
Use a FULL OUTER JOIN between daily_metrics filtered for date D and cumulative_metrics (which holds yesterday's cumulative values) on content_id, then compute today's cumulative as COALESCE(yesterday_cumulative, 0) + COALESCE(today_daily, 0). This ensures all content_ids from either table are included, with missing values treated as zero.
Pro tip: Mention that you'd validate the result by checking that the cumulative value for each content_id is non-decreasing over time and that the total sum matches the sum of daily metrics up to date D. Also, clarify assumptions about data freshness and time zones.
Identify that daily_metrics contains per-day increments and cumulative_metrics contains yesterday's cumulative totals. The goal is to compute today's cumulative per content_id for date D, including all content_ids from either table.
Filter daily_metrics for date D to get today's increments. Use cumulative_metrics as-is since it holds yesterday's cumulative values. Ensure both tables are keyed by content_id.
Join the filtered daily_metrics and cumulative_metrics on content_id using a FULL OUTER JOIN to include content_ids that appear in either table.
For each content_id, calculate today's cumulative as COALESCE(yesterday_cumulative, 0) + COALESCE(today_daily, 0). Use COALESCE to handle NULLs from the outer join.
Select content_id and the computed cumulative value. Optionally, validate by checking that the cumulative is non-decreasing and that the sum matches the total daily increments up to date D.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.