2014-02-25 78 views
2

我有一個表格,從任務返回分鐘,我想轉換成小時和分鐘。mysql分鐘到幾小時和幾分鐘

我的選擇是:

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; 

所以這回從我的桌子和1.67100分鐘時60分 我希望得到的結果1h40m小時和分鐘。

這可能嗎?我怎樣才能將數字分成60,並將小數修改爲60?

謝謝!

回答

6

你應該查找FLOOR()函數,簡單的數學你需要像

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

使用以下事實:小時=地板/ 60 分鐘=(-hours * 60

0

。這工作!謝謝!

select 
    m.mat_nome as 'Matéria', 
    CONCAT(
     FLOOR(
      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 
     ),'h', 
     MOD(
      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) 
    , 'm') 
    as 'tempo' from estudos_realizados e 
left join materias m on e.mat_id = m.mat_id; 
相關問題