在为什么使用 TimescaleDB 而不是关系数据库?文章以下示例是针对双时间用例给出的
SELECT
time_bucket('1 day', time) AS day,
asset_code,
last(price, time_recorded)
FROM prices
WHERE time > '2017-01-01'
GROUP BY day, asset_code
ORDER BY day DESC, asset_code;
如果我们假设prices
表包含recorded_by 列,是否可以编写一个同时返回time_recorded 和recorded_by 列的查询?
例如,给定以下输入:
+------------------+------------+-------+------------------+-------------+
| time | asset_code | price | time_recorded | recorded_by |
+------------------+------------+-------+------------------+-------------+
| 2019-08-08 12:00 | 1 | 9 | 2019-08-08 12:00 | foo |
| 2019-08-09 15:30 | 1 | 10 | 2019-08-09 15:30 | foo |
| 2019-08-08 12:00 | 1 | 9.5 | 2019-08-09 15:00 | bar |
+------------------+------------+-------+------------------+-------------+
您会期望以下输出:
+------------+------------+-------+------------------+-------------+
| day | asset_code | price | time_recorded | recorded_by |
+------------+------------+-------+------------------+-------------+
| 2019-08-09 | 1 | 10 | 2019-08-09 15:30 | foo |
| 2019-08-08 | 1 | 9.5 | 2019-08-09 13:00 | bar |
+------------+------------+-------+------------------+-------------+