I have written like this.I feel this is complex.
SEL B.STARTDATE,COALESCE(MAX(STARTDATE) OVER( PARTITION BY 3 ORDER BY STARTDATE ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING)-1,CAST('9999-12-31' AS DATE)) AS DW_EXPR_DT
FROM
(SEL A.DD as STARTDATE, RANK() OVER(ORDER BY DD) RN
FROM
(
SEL DISTINCT
CASE WHEN DAYOFWEEK(CALENDAR_DATE) =2 THEN CALENDAR_DATE
ELSE
CASE WHEN CALENDAR_DATE
I have written like this.I feel this is complex.
SEL B.STARTDATE,COALESCE(MAX(STARTDATE) OVER( PARTITION BY 3 ORDER BY STARTDATE ROWS BETWEEN 1 FOLLOWING AND 1 FOLLOWING)-1,CAST('9999-12-31' AS DATE)) AS DW_EXPR_DT
FROM
(SEL A.DD as STARTDATE, RANK() OVER(ORDER BY DD) RN
FROM
(
SEL DISTINCT
CASE WHEN DAYOFWEEK(CALENDAR_DATE) =2 THEN CALENDAR_DATE
ELSE
CASE WHEN CALENDAR_DATE