Untitled
WITH aggregated_data AS ( SELECT participant_id, session_id, DATETIME_TRUNC(time, MINUTE) AS interval_start, AVG(heart_rate) AS avg_heart_rate, AVG(rr_interval) AS avg_rri, AVG(temperature1) AS avg_skin_temp FROM ( SELECT participant_id, session_id, time, heart_rate, NULL AS rr_interval, NULL AS temperature1 FROM `clean_hop_heart_rate` UNION ALL SELECT participant_id, session_id, time, NULL, rr_interval, NULL FROM `clean_hop_rri` UNION ALL SELECT participant_id, session_id, time, NULL, NULL, temperature1 FROM `clean_hop_skin_temp` ) combined_data GROUP BY participant_id, session_id, interval_start ) SELECT participant_id, session_id, interval_start AS DateTime, avg_heart_rate, avg_rri, avg_skin_temp FROM aggregated_data ORDER BY participant_id, session_id, interval_start;
Leave a Comment