KLine生成(所有数据) - Xiaotian0617/Center GitHub Wiki

将kline(1m分钟)中的所有数据,按3分钟,5分钟... 分片存入另一张表

SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_3m"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(3m);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_5m"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(5m);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_15m" 
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(15m);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_30m"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(30m);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_1h"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(1h);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_2h"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(2h);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_4h"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(4h);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_6h"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(6h);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_12h" 
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(12h);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_1d"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(1d);
SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_3d"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(3d);
 SELECT LAST("close") AS "close", MAX("high") AS "high", MIN("low") AS "low", FIRST("open") AS "open", SUM("volume") AS "volume", FIRST("onlyKey") AS "onlyKey" 
  INTO "TopCoinDB"."autogen"."kline_1w"
  FROM "TopCoinDB"."autogen"."kline" 
  GROUP BY *,time(1w);