【问题标题】:AWS Athena [Presto] How to receive data from the past 7 days only?AWS Athena [Presto] 如何仅接收过去 7 天的数据?
【发布时间】:2021-05-09 05:57:49
【问题描述】:

我经历了多个类似的线程,但由于某种原因仍然无法使其正常工作。我有这个查询,目前正在从一月份的 stage_date 中提取所有数据,但我希望能够仅获取过去一周(7 天)的数据。当我对与此类似的问题完成其他一些答案时,我收到一个错误,例如 > cannot be applied to varchar, date 或类似的东西。 (当我将 > currentdate 公式放入查询中时)

    select reason_code, service_category, stage_date,
    case when reason_code LIKE 'UAR' 
    then 'Unauthorized Return'       
    else 'FALSE'
    end as "reason_long",
    
    case when service_category like 'CRED'
    then 'Credit Approved'
    else 'FALSE'
    end as "service_long"
    from "table.name"
    where
    stage_date like '01%'
    order by customer_name,
    stage,
    reason_code

【问题讨论】:

  • stage_date的数据类型是什么?请使用 WHERE 和当前日期展示您的尝试

标签: sql date presto


【解决方案1】:

如果 stage_date 是字符串类型,则将其转换为日期:

WHERE date(stage_date) >= current_date() - INTERVAL 7 DAY

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 2021-02-19
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多