Created
April 26, 2019 17:48
-
-
Save georgewfraser/6c06b62fa373668d59a242a04b260c35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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