My dataset looks like this in teradata:
╔═══════════╦══════════╦══════╗
║ studentid ║ date ║ days ║
╠═══════════╬══════════╬══════╣
║ 1000 ║ 2/1/2017 ║ 25 ║
║ 1000 ║ 3/8/2017 ║ 30 ║
║ 1000 ║ 4/4/2017 ║ 80 ║
║ 1000 ║ 5/1/2017 ║ 81 ║
║ 1001 ║ 1/1/2017 ║ 60 ║
║ 1001 ║ 2/1/2017 ║ 20 ║
║ 1001 ║ 4/1/2017 ║ 81 ║
╚═══════════╩══════════╩══════╝
I would like to have a new column (flag) that should indicate 1 on rows if the two recent dates have either 80 or 81. If not 0.
For Student 1001, it should be 0 for all rows because the last two dates are not 80 or 81. it needs to take the last two dates. even though 1001 has 81, the 2nd last date has 20, so the flag needs to be 0 for both
Desired Output :
╔═══════════╦══════════╦══════╦══════╗
║ studentid ║ date ║ days ║ flag ║
╠═══════════╬══════════╬══════╬══════╣
║ 1000 ║ 2/1/2017 ║ 25 ║ 0 ║
║ 1000 ║ 3/8/2017 ║ 30 ║ 0 ║
║ 1000 ║ 4/4/2017 ║ 80 ║ 1 ║
║ 1000 ║ 5/1/2017 ║ 81 ║ 1 ║
║ 1001 ║ 1/1/2017 ║ 60 ║ 0 ║
║ 1001 ║ 2/1/2017 ║ 20 ║ 0 ║
║ 1001 ║ 4/1/2017 ║ 81 ║ 0 ║
╚═══════════╩══════════╩══════╩══════╝