Mysql事件总结一个表

时间:2013-10-01 16:32:38

标签: php mysql events procedure

我想创建一个日常事件,我将用它来“插入summa_table 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不同)我非常感谢你的帮助。

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

0 个答案:

没有答案
相关问题