Skip to content

Instantly share code, notes, and snippets.

@dmeehan1968
Last active March 14, 2018 15:30
Show Gist options
  • Save dmeehan1968/3fdc92d7a9bb0f8efa36ffb17b3742b2 to your computer and use it in GitHub Desktop.
Save dmeehan1968/3fdc92d7a9bb0f8efa36ffb17b3742b2 to your computer and use it in GitHub Desktop.
Combine Heart Rate and Step in MySQL from HealthKit data export
select STR_TO_DATE(CONCAT(H.date, ' ', H.time), '%d/%m/%Y %H:%i') as datetime, H.min, H.max, coalesce(S.steps,0) as steps from heartrate H
left join steps S on
(H.date = S.date or H.date is null and S.date is null)
and
(H.time = S.time or H.time is null and S.time is null)
order by H.date, H.time
select
STR_TO_DATE(CONCAT(H.date, ' ', H.time), '%d/%m/%Y %H:%i') as datetime,
H.min,
H.max,
coalesce(S.steps,0) as steps
from heartrate H
left join steps S on
(H.date = S.date or H.date is null and S.date is null)
and
(H.time = S.time or H.time is null and S.time is null)
group by date(datetime)
having hour(datetime) >= 0 and hour(datetime) <= 7
order by datetime
limit 10000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment