This is a direct translation of your narrative, it will return 'Y' starting with the 3rd consecutive row:
CASE
WHEN salary = MIN(salary) OVER (PARTITION BY employee_id ORDER BY pay_period ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING)
AND salary = MIN(salary) OVER (PARTITION BY employee_id ORDER BY pay_period ROWS BETWEEN 2 PRECEDING AND 2 PRECEDING)
THEN 'Y'
ELSE 'N'
END
Dieter
↧