【问题标题】:how to write datetime <= (minus some days) in teradata case statement如何在 teradata 案例语句中编写 datetime <=(减去几天)
【发布时间】:2021-11-17 16:33:33
【问题描述】:

我必须编写一个 sql 查询,我需要提取 30 天减去几天的数据,

类似这样,日期时间

我可以在 teradata 中写入的最佳方式是什么?

提前致谢:)

【问题讨论】:

    标签: datetime teradata case-statement teradata-sql-assistant teradatasql


    【解决方案1】:

    基于时间戳,正好是 5 天,例如2021-09-24 13:42 -> 2021-09-19 13:42

     where timestamp_column <= current_timestamp - interval '5' day
    

    从午夜开始的全天:

     where timestamp_column <= current_date - 5
    

    【讨论】:

    • 谢谢!但是,如果我要查找上个月的数据而不是当前时间戳怎么办。例如。 2021-09-31 00:00:00.000 减去 5 天到 2021-08-26 00:00:00.000
    • 嗯,你确实在你的问题中写了这个。上个月最后一天:last_day(add_months(current_date,-1))
    猜你喜欢
    • 2013-08-18
    • 1970-01-01
    • 1970-01-01
    • 2018-12-29
    • 2012-06-24
    • 2023-01-26
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    相关资源
    最近更新 更多