Google Interview Question

Find out rolling sum for previous 7 days by using SQL

Interview Answer

Anonymous

Aug 18, 2022

Use a CTE to filter down to last 7 days then take the running sum using a window function with recent_dat as (select score, event_date from tab where event_date >= today() -7) select event_date, sum(score) over(order by event_date) as running_sum from recent_dat