MS SQL Server 2008.
I have a table that records patient visits. This table has three columns:
visit_date - the date of the visit
clinic_id - the identity of the clinic where the visit was made
npi_points - a value we measure for the patient on each visit.
Can someone help me with a query that returns the average change in npi_points between the 1st and 2nd visits, 1st and 3rd visits, and 1st and 4th visit?
I also need the same values for a clinic that has an id of 0.
Something likes this:
Visit Total average change Clinic "0" average change
2nd 12.34 11,54
3rd 15.98 14,74
4th 18,65 18,6