gpt4 book ai didi

sql - 查询股票数据时间范围的变化

转载 作者:行者123 更新时间:2023-12-02 02:07:41 24 4
gpt4 key购买 nike

我正在寻找一个简单的查询,可以将较低时间范围内的股票数据更改为较高时间范围内的股票数据。考虑下表

                          Open    High    Low    Close   Volume
Date
1999-01-04 10:22:00 1.1801 1.1819 1.1801 1.1817 4
1999-01-04 10:23:00 1.1817 1.1818 1.1804 1.1814 18
1999-01-04 10:24:00 1.1817 1.1817 1.1802 1.1806 12
1999-01-04 10:25:00 1.1807 1.1815 1.1795 1.1808 26
1999-01-04 10:26:00 1.1803 1.1806 1.1790 1.1806 4
1999-01-04 10:27:00 1.1801 1.1801 1.1779 1.1786 23
1999-01-04 10:28:00 1.1795 1.1801 1.1776 1.1788 28
1999-01-04 10:29:00 1.1793 1.1795 1.1782 1.1789 10
1999-01-04 10:31:00 1.1780 1.1792 1.1776 1.1792 12
1999-01-04 10:32:00 1.1788 1.1792 1.1788 1.1791 4

每 1 分钟更新一次。我怎样才能通过查询将其更改为说 2 分钟数据?

最佳答案

你想对事物进行分组:

select floor(time/2) as time,
sum(volume) as volume,
max(case when time = 2*floor(time/2) then open end) as open,
max(high) as high,
max(low) as low),
max(case when time = 2*floor(time/2)+1 then close end) as close
from t
group by floor(time/2)

打开和关闭的公式可以使用 row_number() 变得更简单和更通用,但您需要指定数据库。

关于sql - 查询股票数据时间范围的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14204260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com