SQL在Teradata中滚动了13个月(SQL Rolling 13 months in Teradata)

编程入门 行业动态 更新时间:2024-10-17 15:30:30
SQL在Teradata中滚动了13个月(SQL Rolling 13 months in Teradata)

我正在尝试以下查询从某个表中获取最后13个滚动月份。 我一直收到错误'期望在where关键字和年度关键字之间'。 似乎它是基本的东西,但我似乎无法弄明白。 我也尝试过括号,但它仍然给我一个错误。

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'))

I'm trying the below query to get the last 13 rolling months from a certain table. I keep getting the error 'expected something between the where keyword and the year keyword'. Seems like it's something basic but I can't seem to figure it out. I tried putting parentheses too but it still gives me an error.

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'))

最满意答案

您正在将整数与日期进行比较。 如何使用日期呢? 如果您没有未来数据,那么这应该足够了:

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

You are comparing an integer to a date. How about just using dates? If you have no future data, then this should be sufficient:

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

更多推荐

本文发布于:2023-08-07 12:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464503.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动了   个月   SQL   Teradata   months

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!