- 已关闭**。此问题为opinion-based。当前不接受答案。
- 想要改进此问题吗?**请更新此问题,以便editing this post可以用事实和引文来回答。
3天前关闭。
Improve this question
我有一个表,其中的行如下所示:
ts,ticker,m1,m5,m15,m30,h1,h2,h4,d1,high,vwap,low
2020-12-03 00:00:00.000000,DOGEUSDT,0.00336,0.00336,0.00336,0.00336,0.00336,0.00336,0.00336,0.00336,0.003366,0.0033595364,0.003356
2020-12-03 00:01:00.000000,DOGEUSDT,0.00336,0.00336,0.00336,0.00336,0.00336,0.00336,0.00336,0.00336,0.003371,0.0033696603,0.003365
2020-12-03 00:02:00.000000,DOGEUSDT,0.00337,0.00337,0.00337,0.00337,0.00337,0.00337,0.00337,0.00337,0.003376,0.0033727777,0.00337
2020-12-03 00:03:00.000000,DOGEUSDT,0.00337,0.00337,0.00337,0.00337,0.00337,0.00337,0.00337,0.00337,0.003376,0.0033747195,0.003373
查询始终相同:对于特定的股票代码,返回某个时间范围内的聚合数据。
因此,在聚合数据中,时间戳应该是第一条记录(按时间排序),而自动收报机(在所有返回行中都相同)也应该来自第一行。
我已经这样做了:
SELECT
(array_agg(ts))[1] as ts,
(array_agg(ticker))[1] as ticker,
这一条似乎也起作用了:
SELECT
min(ts) as ts,
min(ticker) as ticker,
现在,这个也可以:
SELECT
min(ts) as ts,
min(ticker) as ticker,
FROM ...
GROUP BY ts, ticker
LIMIT 1
推荐的方法是什么?为什么?
1条答案
按热度按时间nfzehxib1#
上面编写的所有查询返回不同的数据。要更清楚地了解这一点:
如果需要按日期对行进行排序,并且之后只返回前几个值,则可以使用以下查询
如果你需要使用agregate函数,那么试试这个查询:
这些查询返回相同的数据: