【问题标题】:SQL Rolling 13 months in TeradataTeradata 中的 SQL 滚动 13 个月
【发布时间】:2016-02-17 02:33:51
【问题描述】:

我正在尝试使用以下查询从某个表中获取过去 13 个滚动月份。我不断收到错误“预计 where 关键字和 year 关键字之间存在某些内容”。似乎这是基本的东西,但我似乎无法弄清楚。我也试过加括号,但它仍然给我一个错误。

select  count(*)
from t
where year(creat_dt) * 100 + month(creat_dt) BETWEEN trunc(add_months(current_date,-13),'MM') AND last_day(current_date,'MM'))

【问题讨论】:

    标签: sql teradata


    【解决方案1】:

    您正在将整数与日期进行比较。只使用日期怎么样?如果您没有未来的数据,那么这就足够了:

    select  count(*)
    from t
    where creat_dt >=  trunc(add_months(current_date, -13), 'MM') 
    

    【讨论】:

      猜你喜欢
      • 2018-09-30
      • 2013-10-06
      • 2021-08-30
      • 2017-08-16
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 1970-01-01
      • 2021-07-31
      相关资源
      最近更新 更多