mysql分钟到小时和分钟 [英] mysql minutes to hours and minutes

查看:84
本文介绍了mysql分钟到小时和分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表,该表返回任务的分钟数,我想将其转换为小时数和分钟数.

I have a table that return minutes from a task and I'd like to convert into hours and minutes.

我的选择是:

select
m.mat_nome as 'Matéria',
round(
    sum(
        case when Hour(TIMEDIFF(est_horario_inicial, est_horario_final))*60 = 0 
            then Minute(TIMEDIFF(est_horario_inicial, est_horario_final))
            else Hour(TIMEDIFF(est_horario_inicial, est_horario_final))*60
        end
    )/60
 ,2)
as 'tempo' from estudos_realizados e
left join materias m on e.mat_id = m.mat_id; 

因此,这是从我的桌子返回100分钟的时间,而除以60则返回1.67. 我想得到的结果是1h40m小时和分钟.

so this is returning 100 minutes from my table and 1.67 when divided by 60. I'd like to get the result 1h40m The hours and minutes.

这可能吗?如何将数字除以60,并将小数位数修改为60?

This is possible? How can I divide the number to 60 and mod the decimals to 60?

谢谢!

推荐答案

您应该查找FLOOR()函数和简单的数学运算.您需要类似

You should look up FLOOR() function, and simple math. You need something like

CONCAT(FLOOR(minutes/60),'h ',MOD(minutes,60),'m') 

这篇关于mysql分钟到小时和分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆