我需要从一个查询中获取 OHLC 值
SELECT [Open] -- first row value
,[High] -- max(High)
,[Low] -- min(low)
,[Close]-- last row value
FROM [Forex] where Symbol ='EURUSD' and
[timestamp] between '2013-07-18 01:00:00.000' and '2013-07-18 02:00:00.000'
我希望该查询有 12 小时的详细信息。我的意思是我需要获得 12 条每小时 OHLC 值的记录
任何人都可以帮助查询。 如何使用聚合函数在 MySQL 查询中获取分组记录的第一条和最后一条记录?在 MYSQL 中有实现,我需要在 SQL 服务器中
编辑:表的结构
CREATE TABLE [dbo].[Forex](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Symbol] [varchar](100) NOT NULL,
[TimeStamp] [datetime] NOT NULL,
[Bid] [decimal](18, 5) NOT NULL,
[Ask] [decimal](18, 5) NOT NULL,
[Open] [decimal](18, 5) NOT NULL,
[High] [decimal](18, 5) NOT NULL,
[Low] [decimal](18, 5) NOT NULL,
[NetChange] [decimal](18, 5) NOT NULL,
[PerChange] [decimal](18, 5) NOT NULL,
CONSTRAINT [PK_Forex] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
和索引
CREATE NONCLUSTERED INDEX [index_Forex_29_85575343__K2_K1] ON [dbo].[Forex]
(
[Symbol] ASC,
[Id] DESC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]