Mysql使用事件从几个表插入数据

时间:2018-04-01 19:28:39

标签: mysql events select

我有代码:

SET GLOBAL event_scheduler = ON;
delimiter |
CREATE EVENT `ex_test` 
ON SCHEDULE EVERY 5 MINUTE

DO BEGIN
        INSERT INTO exchange_value(first_coin, second_coin, price, volume, `exchange`)
        SELECT first_coin, second_coin, AVG(price), AVG(volume), `exchange`
        FROM (
                SELECT first_coin, second_coin, price, volume, 'bibox' AS 'exchange'
                FROM exchange_bibox 
                UNION ALL
                SELECT first_coin, second_coin, price, volume, 'binance' AS 'exchange'
                FROM exchange_binance
        ) AS subquery;

END |

delimiter ;

此代码仅保存一条记录。当我添加GROUP BY first_coin查询时保存少量记录,但不是所有数据,因为记录是分组的。我如何保存所有记录?我无法使用group byjoin。 输入数据是来自exchange_...表的每列的所有记录,而输出数据应该组合成一个输入数据。

0 个答案:

没有答案