简体   繁体   English

在SQL中将分钟转换为小时和十进制

[英]Convert minutes into hour and decimal in SQL

I have been referring this solution Format minutes into hours and minutes as a decimal number in T-SQL 我一直在引用此解决方案, 在T-SQL中将分钟格式设置为小时和分钟,以十进制数表示

but what I want is the value after decimal should represent the correct fraction? 但是我想要的是小数点后的值应该代表正确的分数?

On converting 30 minutes to hours, this formula is incorrect 将30分钟转换为小时时,此公式不正确

select 30/60+(30%60)/100.0 --0.30 选择30/60 +(30%60)/100.0 --0.30

where as the result should be: 结果应为:

select 30*0.0166667 选择30 * 0.0166667

You have to just divide minutes by 60 . 您只需将分钟数除以60。 you can use below query. 您可以使用以下查询。

SELECT 30/60.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM