Skip to content

Instantly share code, notes, and snippets.

@moxie
Created October 24, 2013 23:59
Show Gist options
  • Save moxie/7147249 to your computer and use it in GitHub Desktop.
Save moxie/7147249 to your computer and use it in GitHub Desktop.
SET @a := 0;
SELECT
@a := @a + 1 as "Rank",
tag_id as "Tag ID",
FROM_UNIXTIME(MIN(timestamp), '%H:%i:%S') as "Start Time",
FROM_UNIXTIME(MAX(timestamp), '%H:%i:%S') as "Finish Time",
SEC_TO_TIME(TIMESTAMPDIFF(second, FROM_UNIXTIME(MIN(timestamp)), FROM_UNIXTIME(MAX(timestamp)))) as "Total Time",
SEC_TO_TIME(TIMESTAMPDIFF(second, FROM_UNIXTIME(MIN(timestamp)), FROM_UNIXTIME(MAX(timestamp))) / 3.1) as "Pace",
TIMESTAMPDIFF(second, FROM_UNIXTIME(MIN(timestamp)), FROM_UNIXTIME(MAX(timestamp))) as "Seconds"
FROM timing_test
GROUP BY timing_test.tag_id
ORDER BY TIMESTAMPDIFF(second, FROM_UNIXTIME(MIN(timestamp)), FROM_UNIXTIME(MAX(timestamp))) DESC
-- Rank Tag ID Start Time Finish Time Total Time Pace Seconds
-- 1 Joe 13:58:47 14:05:34 00:06:47 00:02:11 407
-- 2 Bob 13:50:00 13:55:00 00:05:00 00:01:37 300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment