use hahn;

$table_input_base           = "//home/webmaster/prod/analytics/mailings/base";
$table_output_root          = "//home/webmaster/prod/analytics/mailings/history";
$table_output               = $table_output_root || "/" || cast(CurrentUtcDate() as String);

insert into $table_output
    with truncate
select 
    *
from $table_input_base
order by
    UserId,
    Email,
    HostUrl
