I have a query to return sample values for each employee per calendar year, and a column that checks (yes/no) if the sample value is >= 60,000.
My initial data:
Employee_ID Calendar_Year Sample_Value Sample_Check
1234 2020 55,000 No
1234 2021 70,000 Yes
1234 2022 50,000 No
3456 2020 80,000 Yes
3456 2021 40,000 No
3456 2022 65,000 Yes
5678 2020 30,000 No
5678 2021 70,000 Yes
5678 2022 90,000 Yes
I would like to get this result, because this employee is the only one with "yes" for 2 consecutive calendar years.
Employee_ID Calendar_Year Sample_Value Sample_Check
5678 2022 90,000 Yes
I have looked up similar questions but could not find something that solves my issue. I have also looked into LAG and LEAD but need help in understanding if they can give me the result I want.