Created
October 24, 2013 23:50
-
-
Save moxie/7147155 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Given this data | |
-- | |
-- tag_id timestamp | |
-- ---------------------- | |
-- Joe 1382637527 | |
-- Joe 1382637934 | |
-- Bob 1382637000 | |
-- Bob 1382637300 | |
-- How can I modify this query to yield rank based on the lowest time to highest | |
--------------------------------------------------------------------------------- | |
SELECT | |
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" | |
FROM timing_test | |
GROUP BY timing_test.tag_id | |
-- Currently the above query yields the following result | |
-- | |
-- Tag ID Start Time Finish Time Total Time Pace | |
-- Bob 13:50:00 13:55:00 00:05:00 00:01:37 | |
-- Joe 13:58:47 14:05:34 00:06:47 00:02:11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment