Below is the simplified version of the Table.
My query is select all the patientIds where the last X Test Result is over10. Result should be only patientID 1 and 3.
There are over 30k records in this table. I couldn’t figure out a better way to get this done.
PatientId Test Result Date
1 X 11 2011/05/11
1 X 5 2005/05/11
1 Y 5 2011/05/11
2 X 5 2011/05/11
2 X 12 2005/05/11
2 Z 12 2011/05/11
3 X 16 2011/05/11
4 X 9 2005/05/11
I would do something like this: