我有一个刻度值表,如下所示:
这是为进行小型交换而创建的,因此数据非常离散
+-----+------------+------------+---------------------+
| id | price | size | time |
| 1 | 0.78 | 0.3 | 2018-06-22 21:32:11|
| 2 | 0.77 | 0.23 | 2018-06-22 21:32:13|
| 3 | 0.8 | 0.4 | 2018-06-22 21:33:15|
| 4 | 0.6 | 0.35 | 2018-06-22 21:56:19|
| 5 | 0.7 | 0.33 | 2018-06-22 22:09:08|
我想从上表中生成OHLCV数据,并填补以下空白:
+-----+------------+------------+---------------------+
| id | ohlc | size | time |
| 1 | | 0.93 | 2018-06-22 21:30:00|
| 2 | some | 0 | 2018-06-22 21:35:00|
| 3 | values | ... | ... |
| 4 | | 0 | 2018-06-22 22:00:00|
| 5 | | 0.33 | 2018-06-22 22:05:00|
该表用没有交易数据的0填充空白。
我想知道:
我已经阅读了其他堆栈溢出问题以及这些站点的内容:
How To Get ohlc Value In mysql
Generate OHLC Bars from Tick Data
但是我仍然不了解其背后的机制。
例如, 这两个示例都从两个表中选择数据:
select
c1.order_date as date,
(SELECT c2.price
FROM trade c2
WHERE c2.id = MIN(c1.id)) AS open,
MAX(c1.price) AS high,
MIN(c1.price) AS low,
(SELECT c2.price
FROM trade c2
WHERE c2.id = MAX(c1.id)) AS close
FROM trade c1
where
GROUP BY year(c1.order_date), month(c1.order_date), DAY(c1.order_date)
ORDER BY c1.order_date ASC
为什么c1和c2有两个表?
SELECT c2.price FROM trade c2 WHERE c2.id = MIN(c1.id)
语法错误吗?因为在FROM
之后有trade c2
似乎不合适。我无法测试他的代码,因为我无法理解他的方案。有人可以给我解释一下吗?
谢谢大家!