0

我想创建一个日常活动,用于制作“插入到汇总表 SELECT []”中。该活动将在每天上午 10:00 执行。

  • 这是我将用来插入数据的汇总表:
create table attemptsub_carrierday_sum (
    id              int(11) not null AUTO_INCREMENT,
    time        date    not null,
    country     int(11) not null,
    id_carrier  int(11) not null,
    attempts    int(11) not null,
    optins      int(11) not null,
    PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 
  • 这是我将用于插入语句的选择:
INSERT INTO attemptsub_carrierday_sum (time, country, id_carrier, attempts, optins) SELECT DATE(ahs.periodo) as time, co.id as country, ahs.id_carrier, SUM(ahs.attempts) as attempts, 
    SUM(case when ahs.api_code = 100 AND ahs.api_wasactive = 1 
        AND ahs.api_sending_short_code > 0
        then ahs.attempts else 0 end) as optins
    FROM `attemptsub_hourly_summarized` as ahs
    LEFT JOIN carrier as ca ON ahs.id_carrier= ca.id_carrier
    LEFT JOIN country as co ON ca.country_id = co.id
    GROUP BY co.id, ahs.id_carrier, time
    ORDER BY `time` DESC, country, id_carrier;

我的问题是我从来没有在 MySQL 中做过和事件(我在 oracle 做过工作,但 mysql 是不同的),我非常感谢你的帮助。

如果您需要更多信息,我将很乐意提供帮助。

4

0 回答 0