我有代码:
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 by
和join
。
输入数据是来自exchange_...
表的每列的所有记录,而输出数据应该组合成一个输入数据。