Skip to content

Instantly share code, notes, and snippets.

@wouterds
Last active February 21, 2019 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wouterds/22ba2f0e3bda4e25aacdb8037f4a4e0f to your computer and use it in GitHub Desktop.
Save wouterds/22ba2f0e3bda4e25aacdb8037f4a4e0f to your computer and use it in GitHub Desktop.
SELECT
sensors.type,
samples.value,
DATE_FORMAT(
CONVERT_TZ(
samples.createdAt,
'+00:00',
'+01:00'
),
'%Y-%m-%d %h:%i %p'
) AS time
FROM samples
JOIN sensors ON sensors.id = samples.sensorId
WHERE samples.createdAt > (NOW() - INTERVAL 12 HOUR) AND samples.value = 0
ORDER BY samples.createdAt ASC, sensors.type ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment