I want to implement below logic in Presto SQL:
DECLARE @StartDate DATE = '2016-10-01' ; DECLARE @EndDate DATE = '2021-05-02' ;
WHILE (@StartDate <= @EndDate)
BEGIN
print @StartDate;
DECLARE @12MonthStartDate date
select @12MonthStartDate = (SELECT DateAdd(YEAR, -1, @StartDate));
DECLARE @12MonthEndDate date
select @12MonthEndDate = @StartDate ;
select * from MyTable where Date >= @12MonthStartDate and Date <= @12MonthStartDate
Based on above results, we need to do the rolling 12 months and insert the max date values into the table.
Note: we are using Presto SQL in Amperity tool.
set @StartDate = DATEADD(day, 1, @StartDate);
END;
Can any one please help with how to implement above logic in Presto SQL?
Thanks