I need to write a teradata query. One of the column in source is defined as DATE (END_DT). Source records should be selected as per below condition.
1. END_DT is the column which stores the date.
2. Records should be selected only for the latest completed quater.
Then latest completed quater is 31-03-12 so only first three records should be selected.
This is the data i tried,
SEL a.* FROM dat a
JOIN Sys_Calendar.calendar b
JOIN (SEL calendar_date, CASE WHEN quarter_of_year=1 THEN year_of_calendar - 1 ELSE year_of_calendar END AS years,
CASE WHEN quarter_of_year =1 THEN 4 ELSE quarter_of_year - 1 END AS qtr FROM Sys_Calendar.calendar ) c