I have query result/table with columns: id, date. Like:
id , date
0001 , 2012.01.20
0001 , 2014.10.12
0001 , null
0001 , 2017.05.21
0001 , 2017.08.15
0002 , null
0002 , 2013.06.05
0002 , 2017.08.11
0003 , null
0004 , 2011.12.25
0005 , 2017.12.10
0006 , null
0006 , 2013.04.23
.
.
.
etc...
It's an example - in real world there are couple thousand of id's and over one and half million records. How to find records with closest to today future date (id's 0001, 0002, 0005) and these only with null (id 0003), past dates (id 0004) or null and past dates (id 0006) replace with some text. The result should look like:
id , date
0001 , 2017.05.21
0002 , 2017.08.11
0003 , 'replaced text'
0004 , 'replaced text'
0005 , 2017.12.10
0006 , 'replaced text'
.
.
etc...
I hope this example shows exactly what I need.
Thank you for any clues.