【问题标题】:How to get the last n days data in DolphinDB如何在 DolphinDB 中获取最近 n 天的数据
【发布时间】:2019-11-03 10:04:37
【问题描述】:

我如下创建一个表格,

timestamp=[2019.06.01T09:00:00.000 ,2019.06.02T09:00:00.000,2019.06.20T09:00:00.000]
sym = `MS`MS`MS$symbol;                 
price= 49.6 29.46 29.52 ;           
qty = 2200 1900 2100 ;              
t1 = table(timestamp, sym, qty, price)

然后我在 DolphinDB Gui 中执行以下代码, 从 t1 中选择 * 记录集显示 like this。 但我执行以下代码,

days=1000*60*60*24
select * from t1 where timestamp > now()-days*30

如图所示,记录集为空 like this.

如何从dolphindb表中选取最近n天的数据?

【问题讨论】:

    标签: sql dolphindb


    【解决方案1】:

    您的代码有轻微的数据溢出问题。 days 是一个整数(4 个字节),day * 30 的结果超过了整数的最大值。两种修复方法:

    方法一:常数30转30l

    days=1000*60*60*24
    select * from t1 where timestamp > now()-days*30l
    

    方法二:使用temporalAdd函数

    select * from t1 where timestamp > temporalAdd(now(), -30, 'd')
    

    【讨论】:

      猜你喜欢
      • 2019-09-14
      • 1970-01-01
      • 2020-09-03
      • 2019-02-07
      • 1970-01-01
      • 2022-12-28
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      相关资源
      最近更新 更多