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')更多推荐
发布评论