I need to grab the data for the past 12 months. I am using SQL within AWS Athena. Below is my code:
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
Gives me an error: cannot be applied to varchar, date
event_triggered_filed is a string
This is the structure of the date field: 2019-12-04 00:00:00.000
I had same problem I need to get the stating day of the 6th and 12th month from current date.
I have written this, it works for me I hope it will work for other as well.
please refer attached image for query result
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
For Staring day of the 12 month before date.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.