Skip to content

Instantly share code, notes, and snippets.

@georgewfraser
Created April 26, 2019 17:48
Show Gist options
  • Save georgewfraser/6c06b62fa373668d59a242a04b260c35 to your computer and use it in GitHub Desktop.
Save georgewfraser/6c06b62fa373668d59a242a04b260c35 to your computer and use it in GitHub Desktop.
-- SOURCE TABLE: visits (time timestamp) partition by date(time);
-- DEST TABLE: create table daily (day date, visits int)
begin;
create temp table new_visits as
select date(time), count(1)
from visits
where time >= date_sub(@prev_date, interval 5 days);
delete from daily where day in (select day from new_visits);
insert into daily (select * from new_visits);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment