mysql - MySQL data to time value
问题描述
My table does an addition of how much time it takes to finish production.
It spits out values like: 192.5, or 100.25.
I'd like to know how to turn these values into something like this:
120 ---> 120 minutes
140.5 ---> 2 hours, 20 minutes, 30 seconds
30.25 ---> 30 mintes, 15 seconds
The formatting is unimportant, just would like to display time.
解决方案
Crudely (I suspect that this can be written more elegantly)...
SET @x = 30.25;
SELECT FLOOR(@x/60) hours
, FLOOR((@x/ 60-FLOOR(@x/60)) * 60) minutes
, ROUND(((((@x/60)-FLOOR(@x/60))*60)-FLOOR((@x/60-FLOOR(@x/60))*60))*60,0) seconds;
+-------+---------+---------+
| hours | minutes | seconds |
+-------+---------+---------+
| 0 | 30 | 15 |
+-------+---------+---------+
推荐阅读
- python - Google_drive_api 图像 ID
- reactjs - 如何从 Ghost(内容 API)获取图像到 Next.js?
- ag-grid - Ag-grid 分组:仅为一列设置 groupRemoveSingleChildren
- mysql - MySQL - 使用外键插入一行
- vue.js - 如何使用 Vuelidate 异步规则
- logging - 如何使用变量设置 logback.xml 中的根日志级别?
- javascript - Vue 3 Datepicker Typeable True Autocomplete
- junit4 - allure 插件“io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm”正在抛出 VM 崩溃或 system.exit 调用
- python - 如何使用 Python 对基于一个文件的一组文件的内容进行排序
- mongodb - Mongoose 缓存模型吗?