【问题标题】:Subtract 30 days from current date in where clause在 where 子句中从当前日期减去 30 天
【发布时间】:2019-04-29 16:14:24
【问题描述】:

在我的 where 子句中,我只想获取具有今天日期和过去 30 天记录的记录。所以我想要 3-29-19 到 4-29-19 的记录 但我需要这个滚动日期,所以明天是 3-30 到 4-30-19 基本上提取了过去 30 天的记录。

curdate() 让我在优势 sql 中获取当前日期。我在想可能是一个 between 子句之类的。

dateadd(dd,-30,curdate()),

【问题讨论】:

    标签: sql advantage-database-server


    【解决方案1】:

    ADS 允许您直接对日期进行数学运算(如果表中有实际的日期列),因此您可以使用

    WHERE datecol between curdate() - 30 and curdate()
    

    【讨论】:

      【解决方案2】:

      我想应该是这样的:

      where datecol >= timestampadd(SQL_TSI_DAY, -30, current_date())
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-04-29
        • 1970-01-01
        • 2012-06-01
        • 2021-01-04
        相关资源
        最近更新 更多