【问题标题】:How to write a query to fetch data from DB on the basis of timestamp如何编写查询以根据时间戳从数据库中获取数据
【发布时间】:2019-02-18 12:51:34
【问题描述】:

我有一个任务要做,我必须编写一个可以根据时间戳获取数据的查询

  1. 我的数据库中有一个表,有两列,一列是event,另一列是Time
  2. 我要做的是编写一个查询,它可以给我在过去 1 分钟内输入的数据
  3. 我写了一个查询,它给出了正确的结果,但在 sql 5.1 中
  4. 我正在使用 Derby 数据库并面临获取输出的问题

这是我在 derby 中运行查询时遇到的错误

errorSyntax error: Encountered "5"

我的查询是SELECT * FROM test WHERE Time >= CURRENT_TIMESTAMP - INTERVAL 5 minute AND Time <= CURRENT_TIMESTAMP

【问题讨论】:

    标签: sql derby


    【解决方案1】:

    我不确定区间语法,但你可以试试TIMESTAMPADD()

    SELECT *
    FROM test
    WHERE Time >= {fn TIMESTAMPADD(SQL_TSI_MINUTE, -5, CURRENT_TIMESTAMP) }
    AND Time <= CURRENT_TIMESTAMP
    

    【讨论】:

    • 嘿先生SQL_TSI_MINUTE 是什么,因为它显示错误
    • 因为我对此很陌生,无法理解错误,这是我遇到的错误Column 'SQL_TSI_MINUTE' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'SQL_TSI_MINUTE' is not a column in the target table
    猜你喜欢
    • 2020-03-07
    • 2018-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    相关资源
    最近更新 更多