SQL中的小时计算

编程入门 行业动态 更新时间:2024-10-24 22:28:14
本文介绍了SQL中的小时计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我这样做.. !!! DECLARE @minutes AS INT SET @minutes = 1.80 * 100 SELECT @minutes / 60 +(@minutes%60)/ 100.0 AS Hours 它给了我3.000但结果应该是2.20小时 我怎么能实现那个......? 请帮我解决

解决方案

整数。有趣的小恶魔不是他们...... 什么是1.8 * 100? 答案:180 什么是180/60? 答案:3 什么是180%60? 答案:0 所以首先答案是3,而不是2-and-bit。 其次,当你将整数除以小于100(任何数字%60将始终是)100? 答案:0,因为整数算术按定义丢弃了数字的一小部分... 所以,你可能想要考虑在整个浮点数工作...

DECLARE @minutes INT DECLARE @hours INT DECLARE @time decimal ( 5 , 2 )= 1 . 80 SET @hours = floor(@time) SET @minutes =(@ time - @hours)* 100 SET @minutes = @minutes +(@hours * 60 ) SELECT @minutes / 60 +(@min utes% 60 )/ 100 。 0 AS 小时

这个怎么样.......! !!!

I'm doing like this..!!! DECLARE @minutes AS INT SET @minutes = 1.80*100 SELECT @minutes / 60 + (@minutes % 60) / 100.0 AS Hours it gives me 3.000 but the result should be 2.20 hrs how can i acheive that..? pls help me out

解决方案

Integers. Interesting little devils aren't they... What is 1.8 * 100? Answer: 180 What is 180 / 60? Answer: 3 What is 180 % 60? Answer: 0 So first off the answer is 3, not 2-and-a-bit at all. Secondly, What do you get when you integer divide a number less than 60 (as any number % 60 will always be) by 100? Answer: 0, because integer arithmetic throws away fraction parts of numbers by definition... So, probably, you want to consider working in floating point numbers throughout...

DECLARE @minutes INT DECLARE @hours INT DECLARE @time decimal(5,2) = 1.80 SET @hours = floor(@time) SET @minutes = (@time - @hours) * 100 SET @minutes = @minutes + (@hours * 60) SELECT @minutes / 60 + (@minutes % 60) / 100.0 AS Hours

How about this.......!!!!

更多推荐

SQL中的小时计算

本文发布于:2023-10-24 09:35:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523591.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小时   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!