Created a table with some columns of type TIME(3)
Loaded from a CSV file
0:07.763
0:07.783
0:07.276
0:07.484
0:07.127
Running select * from some_table
yields the following:
00:00:07.763
00:00:07.783
00:00:07.276
00:00:07.484
00:00:07.127
My question is: How can I get this to display in a select statement without the leading 0’s ? Something like:
7.763
7.783
7.276
7.484
7.127
tried various permutations of TRIM
but those all failed.
2
Answers
You can use the TIME_FORMAT function to format your times in your query.
Something like this should work:
The
%s
part is the seconds and the%f
part is the microseconds.Exactly for this purpose the function
TIME_TO_SEC()
exists:This is much faster, since the function does a simple mathematical operation (tm.hour * 3600 + tm.minute * 60 + tm.second + tm.microsecond / 1000000) instead of parsing a string before:
But many roads lead to Rome:…