Lets assume i have a table called VISITS containing the following
- VISIT_DATE (TIMESTAMP)
- HEIGHT (NUMBER)
- WAIST (NUMBER)
- WEIGHT(NUMBER)
-
PATIENT_ID (NUMBER)
VISIT_DATE| HEIGHT | WAIST | WEIGHT | PATIENT_ID
10/01/2012 | (null) | 96 | 130 | 44123
11/01/2012 | 1.74 | (null) | 120 | 44123
12/01/2012 | (null) | (null) | 150 | 44123
What I need is a sql select statement to get the most recent value for each column but ignoring the null fields so the output I need would be
The WHERE clause would be
WHERE PATIENT_ID = 44123 ORDER BY VISIT_DATE DESC LIMIT 1
12/01/2012 | 1.74 | 96 | 150 | 44123
As you can see from the output I expect to get from the select I am stepping backwards through each row for the patient until I find a value for each field.
I hope this question is clear and possible, I have searched but haven’t found any real solution up to now, this is going to be used to streamline a medical system being used with hospitals and there is about 100 fields the above is just an example of a few fields to get the concept across of what is required.
Here is SQLfiddle example