Am tyring to model on a dataset with individual person's vitals for a wellness app, imagine like Fitbit. However, these vitals, for a given person are recorded and reported as individual rows. E.g.
TableName: PersonalVitals
PersonID | RecordedTime | VitalType | VitalValue
1 | 17:10 | HR | 72bpm <- Heart rate
1 | 17:10 | RR | 19insp/min <- Respiratory rate
2 | 15:35 | RR | 11insp/min <- Respiratory rate
1 | 17:15 | HR | 76bpm <- Heart rate
Now, on extraction, I need to pivot this data, so that all the vitals that were taken during the same time, are reported together, something like below
PersonID | RecordedTime | HR | RR | SpO2 | BP(Blood Pressure)
1 | 17:10 | 72bpm | 19insp/min | null | null
1 | 17:15 | 76bpm | null | null | null
2 | 15:35 | null | 11insp/min | null | null
How can I achive the above in SQL (sql-server or postgres)?
Thanks
SpO2in your sample data)