【问题标题】:Rolling list of dates in NetezzaNetezza 中的日期滚动列表
【发布时间】:2019-03-15 03:50:12
【问题描述】:

与我提出的here 但与 Sybase SQL 相关的问题类似,我正在寻找我的 where 子句的日期列表,以过滤 Netezza 中的表。

目前,每次使用手动日期运行查询时都需要更新 where 子句,我希望自动执行此操作以使用过去 36 个月的数据,但从上个月末开始。因此,如果今天是 2018 年 10 月 10 日,我希望从 2018 年 9 月 30 日回到 36 个月。

我当前的 Netezza where 子句如下所示:

WHERE

    table.DateCol BETWEEN '2015-10-01' AND '2018-09-30'

我找到了一些示例 here 关于提取本月的最后一天和第一天,但​​我不知道如何将它们连接在一起以使用“BETWEEN”和“AND”获得日期列表

--last_day(now() - interval'36 month') + interval '1 day'  
--last_day(now() - interval'1 month')

任何指针将不胜感激。

【问题讨论】:

    标签: sql netezza


    【解决方案1】:

    你在找这个吗?

    where t.datecol between last_day(current_date - interval '36 month') + interval '1 day' and
                            last_day(current_date - interval '1 month')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多