drop table if exists PxCDMEmailingTemplateStatistics;

create table PxCDMEmailingTemplateStatistics (
  fk_template int not null,
  countries mediumblob not null,
  cities mediumblob not null,
  impressions mediumblob not null,
  platforms mediumblob not null,
  unique_impressions mediumblob not null,
  errors mediumblob not null,
  primary key (fk_template)
) engine=myisam default charset=utf8;

insert into PxCDMEmailingTemplateStatistics
            (fk_template)
values      (1), (219), (87), (278), (205), (283), (286), (296), (298), (299), (310);

update  PxCDMEmailingTemplateStatistics
set     impressions = column_add(impressions,
            'total', ifnull(column_get(impressions, 'total' as int), 0) + 194,
            '2014-10-09 13:00:00', ifnull(column_get(impressions, '2014-10-09 13:00:00' as int), 0) + 1,
            '2014-10-28 14:00:00', ifnull(column_get(impressions, '2014-10-28 14:00:00' as int), 0) + 5,
            '2014-10-28 15:00:00', ifnull(column_get(impressions, '2014-10-28 15:00:00' as int), 0) + 5,
            '2014-10-29 15:00:00', ifnull(column_get(impressions, '2014-10-29 15:00:00' as int), 0) + 27,
            '2014-10-31 11:00:00', ifnull(column_get(impressions, '2014-10-31 11:00:00' as int), 0) + 5,
            '2014-10-31 12:00:00', ifnull(column_get(impressions, '2014-10-31 12:00:00' as int), 0) + 20,
            '2014-10-31 13:00:00', ifnull(column_get(impressions, '2014-10-31 13:00:00' as int), 0) + 5,
            '2014-10-31 14:00:00', ifnull(column_get(impressions, '2014-10-31 14:00:00' as int), 0) + 11,
            '2014-10-31 15:00:00', ifnull(column_get(impressions, '2014-10-31 15:00:00' as int), 0) + 6,
            '2014-10-31 16:00:00', ifnull(column_get(impressions, '2014-10-31 16:00:00' as int), 0) + 26,
            '2014-10-31 17:00:00', ifnull(column_get(impressions, '2014-10-31 17:00:00' as int), 0) + 26,
            '2014-11-03 10:00:00', ifnull(column_get(impressions, '2014-11-03 10:00:00' as int), 0) + 6,
            '2014-11-03 11:00:00', ifnull(column_get(impressions, '2014-11-03 11:00:00' as int), 0) + 5,
            '2014-11-03 16:00:00', ifnull(column_get(impressions, '2014-11-03 16:00:00' as int), 0) + 5,
            '2014-11-04 09:00:00', ifnull(column_get(impressions, '2014-11-04 09:00:00' as int), 0) + 5,
            '2014-11-04 11:00:00', ifnull(column_get(impressions, '2014-11-04 11:00:00' as int), 0) + 5,
            '2014-11-04 16:00:00', ifnull(column_get(impressions, '2014-11-04 16:00:00' as int), 0) + 1,
            '2014-11-05 15:00:00', ifnull(column_get(impressions, '2014-11-05 15:00:00' as int), 0) + 5,
            '2014-11-05 16:00:00', ifnull(column_get(impressions, '2014-11-05 16:00:00' as int), 0) + 5,
            '2014-11-06 13:00:00', ifnull(column_get(impressions, '2014-11-06 13:00:00' as int), 0) + 5,
            '2014-11-07 12:00:00', ifnull(column_get(impressions, '2014-11-07 12:00:00' as int), 0) + 10,
            '2014-11-12 13:00:00', ifnull(column_get(impressions, '2014-11-12 13:00:00' as int), 0) + 5
        ),
        unique_impressions = column_add(unique_impressions,
            'total', ifnull(column_get(unique_impressions, 'total' as int), 0) + 7,
            '2014-10-09 13:00:00', ifnull(column_get(unique_impressions, '2014-10-09 13:00:00' as int), 0) + 1,
            '2014-10-28 14:00:00', ifnull(column_get(unique_impressions, '2014-10-28 14:00:00' as int), 0) + 1,
            '2014-10-28 15:00:00', ifnull(column_get(unique_impressions, '2014-10-28 15:00:00' as int), 0) + 1,
            '2014-10-29 15:00:00', ifnull(column_get(unique_impressions, '2014-10-29 15:00:00' as int), 0) + 1,
            '2014-10-31 11:00:00', ifnull(column_get(unique_impressions, '2014-10-31 11:00:00' as int), 0) + 1,
            '2014-11-03 16:00:00', ifnull(column_get(unique_impressions, '2014-11-03 16:00:00' as int), 0) + 1,
            '2014-11-06 13:00:00', ifnull(column_get(unique_impressions, '2014-11-06 13:00:00' as int), 0) + 1
        ),
        platforms = column_add(platforms,
            'Firefox 8.0', ifnull(column_get(platforms, 'Firefox 8.0' as int), 0) + 2,
            '', ifnull(column_get(platforms, '' as int), 0) + 7,
            'Chrome 38.0.2125.111', ifnull(column_get(platforms, 'Chrome 38.0.2125.111' as int), 0) + 4
        ),
        countries = column_add(countries,
            'NL', ifnull(column_get(countries, 'NL' as int), 0) + 11
        ),
        cities = column_add(cities,
            'NL/07/Hilversum', ifnull(column_get(cities, 'NL/07/Hilversum' as int), 0) + 11
        )
where   fk_template = 278;

update  PxCDMEmailingTemplateStatistics
set     impressions = column_add(impressions,
            'total', ifnull(column_get(impressions, 'total' as int), 0) + 19,
            '2014-10-28 13:00:00', ifnull(column_get(impressions, '2014-10-28 13:00:00' as int), 0) + 3,
            '2014-10-28 15:00:00', ifnull(column_get(impressions, '2014-10-28 15:00:00' as int), 0) + 3,
            '2014-10-28 16:00:00', ifnull(column_get(impressions, '2014-10-28 16:00:00' as int), 0) + 3,
            '2014-10-30 15:00:00', ifnull(column_get(impressions, '2014-10-30 15:00:00' as int), 0) + 3,
            '2014-11-04 09:00:00', ifnull(column_get(impressions, '2014-11-04 09:00:00' as int), 0) + 7
        ),
        unique_impressions = column_add(unique_impressions,
            'total', ifnull(column_get(unique_impressions, 'total' as int), 0) + 4,
            '2014-10-28 13:00:00', ifnull(column_get(unique_impressions, '2014-10-28 13:00:00' as int), 0) + 1,
            '2014-10-28 15:00:00', ifnull(column_get(unique_impressions, '2014-10-28 15:00:00' as int), 0) + 1,
            '2014-10-28 16:00:00', ifnull(column_get(unique_impressions, '2014-10-28 16:00:00' as int), 0) + 1,
            '2014-11-04 09:00:00', ifnull(column_get(unique_impressions, '2014-11-04 09:00:00' as int), 0) + 1
        ),
        platforms = column_add(platforms,
            '', ifnull(column_get(platforms, '' as int), 0) + 4
        ),
        countries = column_add(countries,
            'US', ifnull(column_get(countries, 'US' as int), 0) + 2,
            'NL', ifnull(column_get(countries, 'NL' as int), 0) + 2
        ),
        cities = column_add(cities,
            'US/CA/Mountain View', ifnull(column_get(cities, 'US/CA/Mountain View' as int), 0) + 2,
            'NL/07/Hilversum', ifnull(column_get(cities, 'NL/07/Hilversum' as int), 0) + 2
        )
where   fk_template = 205;
