让我说我的SQL代码得到8048秒:
SUM(DATEDIFF(s, '8/25/2015', '8/26/2015')) as 'Seconds'
如何在分钟和小时内得到相同的答案......但是它们是小数?这是几个小时:
Cast(((SUM(DATEDIFF(s, '8/25/2015', '8/26/2015'))/60.00)/60.00) as decimal(8,2)) as 'Hours'
但我持续2.00小时......应该是2.34小时?
答案 0 :(得分:1)
DATEDIFF返回一个间隔。将其作为浮点数或小数表示,以从数学公式中获得小数结果:
Cast(((SUM(CAST(DATEDIFF(s, '8/25/2015', '8/26/2015') AS decimal(8,2))/60.00)/60.00) as decimal(8,2)) as 'Hours'
答案 1 :(得分:0)
尝试将CAST
语句重新定位到SUM()
:
CAST((SUM(CAST(DATEDIFF(s, [date1], [date2]) AS Decimal(20,2))/60.00)/60.00)) AS Decimal(20,2)) as 'Hours'
现在你设置它的方式,在你施展它之前,这个值可能是四舍五入的