首页 > 解决方案 > SQL Athena 获取过去 12 个月的数据

问题描述

我需要获取过去 12 个月的数据。我在 AWS Athena 中使用 SQL。下面是我的代码:

CREATE
OR REPLACE VIEW response_view AS
SELECT
    "cust"."customer_id",
    "cust"."event_triggered_date"
FROM
    (
        db.population_view pop
        INNER JOIN new_db.manual_response_view cust ON ("pop"."customer_id" = "cust"."customer_id")
    )
    WHERE "cust"."event_triggered_date" > current_date - interval '12' month

给我一个错误:cannot be applied to varchar, date

event_triggered_filed 是一个字符串

这是日期字段的结构:2019-12-04 00:00:00.000

标签: sqlamazon-web-servicesdateamazon-athena

解决方案


尝试这个。

CAST(EVENT_TRIGGERED_DATE AS DATE)

或者

CAST(EVENT_TRIGGERED_DATE AS TIMESTAMP )

数据类型


推荐阅读