本文介绍了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 HoursHow about this.......!!!!
更多推荐
SQL中的小时计算
发布评论