簡體   English   中英

SQL Athena 獲取過去 12 個月的數據

[英]SQL Athena getting the data for the past 12 months

我需要獲取過去 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

嘗試這個。

CAST(EVENT_TRIGGERED_DATE AS DATE)

或者

CAST(EVENT_TRIGGERED_DATE AS TIMESTAMP )

數據類型

我有同樣的問題,我需要從當前日期獲得第 6 個月和第 12 個月的聲明日。

我已經寫了這個,它適用於我,我希望它也適用於其他人。

查詢結果請參考附圖

select current_date as today, date_add('month', -6, (select date(date_format(cast(current_date as date),'%Y-%m-01')))) as Start_of_the_date_6_month_before

在此處輸入圖像描述

日期前 12 個月的起始日。

select current_date as today, date_add('month', -12, (select date(date_format(cast(current_date as date),'%Y-%m-01')))) as Starting_day_of_the_month_12_before

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM