我在一个表中有一列lvl\u tim,它是返回hh:mm:ss的字符串类型。我不能采用datefiff()方法,最终希望对这些值求和。我尝试过:
cast(lvl_tim as int)
我想要的结果是0:10:10,返回0.1683小时。
ktecyv1j1#
你可以采用暴力算法:
WITH yourTable AS ( SELECT '12:34:56' AS time ) SELECT time, CAST(LEFT(time, 2) AS int) + CAST(SUBSTRING(time, 4, 2) AS int) / 60.0 + CAST(SUBSTRING(time, 7, 2) AS int) / (60.0*60.0) AS decimal_hours FROM yourTable;
上述查询的正确输出是 12.58222155 十进制小时,输入时间为 12:34:56 .
12.58222155
12:34:56
1条答案
按热度按时间ktecyv1j1#
你可以采用暴力算法:
演示
上述查询的正确输出是
12.58222155
十进制小时,输入时间为12:34:56
.