3

我有一个由分钟组成的专栏。有没有简单的方法将分钟列拆分为仅显示天、小时、分钟的列?

DURATION              
-----------
67           ==> 1 hour, 7 minutes
1507         ==> 1 day, 1 hour, 7 minutes
23           ==> 23 minutes

我搜索了解决方案,但我没有找到任何类似的解决方案。我想在报告中展示这一点,但试图找到如何解决这个专栏看起来很有意义。持续时间列的计算是这样的。

avg(datediff(MINUTE, ei.SentDate, eo.SentDate)) over(partition by ei.mailbox) as DURATION   
4

2 回答 2

8

谷歌搜索让我在这里http://www.sqlservercentral.com/Forums/Topic490411-8-1.aspx

它说......我刚刚测试过工作......

Declare @theMinutes int
Set @theMinutes = 67 

Select @theMinutes / 1440 as NoDays  -- 1440 minutes per day 
       , (@theMinutes % 1440) / 60 as NoHours -- modulo 1440 
       , (@theMinutes % 60) as NoMinutes -- modulo 60
于 2013-05-03T06:12:12.863 回答
3
create FUNCTION  fun_Date_Friendly (@minutes int)
RETURNS nvarchar(100)
AS
BEGIN
   return CASE 
    when @minutes < 60 then cast( @minutes as varchar(10)) + ' Min'
    when @minutes < 1440 then cast(@minutes/60 as varchar(10)) + ' Hr, ' + cast(@minutes%60 as varchar(10)) + ' Min'
    else cast(@minutes/(1440 ) as varchar(10)) + ' Days, ' + cast((@minutes%1440 )/60 as varchar(10)) + ' Hr, ' + cast(((@minutes%1440 )%60) as varchar(10)) + ' Min'
    end
end
go

然后只需几分钟即可正常工作

select  dbo.fun_Date_Friendly(20) val
于 2016-12-06T07:23:53.143 回答