Sql 我今天试着让它发挥作用,但它只会让事情变得更糟,所以我要把它从OP中删除。我完全同意你的看法。大家都知道,表格不是我写的。我只是照顾它。我想我有可能修正这个邪恶的精确性。但是在学术上,我仍然不明白,我可以得到数据中的值40,然后用数字40测试相同的值,得到

Sql 我今天试着让它发挥作用,但它只会让事情变得更糟,所以我要把它从OP中删除。我完全同意你的看法。大家都知道,表格不是我写的。我只是照顾它。我想我有可能修正这个邪恶的精确性。但是在学术上,我仍然不明白,我可以得到数据中的值40,然后用数字40测试相同的值,得到,sql,sql-server,Sql,Sql Server,我今天试着让它发挥作用,但它只会让事情变得更糟,所以我要把它从OP中删除。我完全同意你的看法。大家都知道,表格不是我写的。我只是照顾它。我想我有可能修正这个邪恶的精确性。但是在学术上,我仍然不明白,我可以得到数据中的值40,然后用数字40测试相同的值,得到不同的结果。我修改了OP.@jollarvia。如果您了解浮点运算的工作原理,并且了解在SUM()中运算顺序是不确定的,那么这就非常有意义了。我完全同意您的看法。大家都知道,表格不是我写的。我只是照顾它。我想我有可能修正这个邪恶的精确性。但是在


我今天试着让它发挥作用,但它只会让事情变得更糟,所以我要把它从OP中删除。我完全同意你的看法。大家都知道,表格不是我写的。我只是照顾它。我想我有可能修正这个邪恶的精确性。但是在学术上,我仍然不明白,我可以得到数据中的值40,然后用数字40测试相同的值,得到不同的结果。我修改了OP.@jollarvia。如果您了解浮点运算的工作原理,并且了解在
SUM()
中运算顺序是不确定的,那么这就非常有意义了。我完全同意您的看法。大家都知道,表格不是我写的。我只是照顾它。我想我有可能修正这个邪恶的精确性。但是在学术上,我仍然不明白,我可以得到数据中的值40,然后用数字40测试相同的值,得到不同的结果。我修改了OP.@jollarvia。如果您了解浮点运算是如何工作的,并且了解在
SUM()
中运算顺序是不确定的,那么这是非常有意义的。您能解释一下为什么浮点运算不能与round一起工作吗?我相信你是对的。decimal(38,20)没有表现出相同的行为,但我想了解更多的原因。round函数的返回类型也是float,因此Sum函数处理float。如果您使用
cast(四舍五入(小时,2)作为十进制(10,4))
这也会起作用,因为Sum函数处理的是定点数据而不是浮点数据。您能解释一下为什么float不能处理四舍五入吗?我相信你是对的。decimal(38,20)没有表现出相同的行为,但我想了解更多的原因。round函数的返回类型也是float,因此Sum函数处理float。如果您使用
cast(四舍五入(小时,2)作为十进制(10,4))
这也会起作用,因为求和函数使用的是定点数据而不是浮点数据。这个答案是最明显的问题说明。同时考虑到@chrisuae的回答,我选择首先将浮点值转换为十进制:求和(四舍五入(转换为十进制(38,10),小时),2))<40。我认为这一天的寓意是:如果你看到浮子,快跑!这个答案是发动机罩下问题最明显的例证。同时考虑到@chrisuae的回答,我选择首先将浮点值转换为十进制:求和(四舍五入(转换为十进制(38,10),小时),2))<40。我认为这一天的寓意是:如果你看到浮子,快跑!
    create table #thisweek ([hours] float, time_user varchar(100))

insert into #thisweek values
(1.58000004291534,  'john.doe'),
(4.32000017166138,  'john.doe'),
(0.620000004768372, 'john.doe'),
(1, 'john.doe'),
(0.680000007152557, 'john.doe'),
(2, 'john.doe'),
(2, 'john.doe'),
(3, 'john.doe'),
(0.790000021457672, 'john.doe'),
(3, 'john.doe'),
(2, 'john.doe'),
(1, 'john.doe'),
(3.32999992370605,  'john.doe'),
(2, 'john.doe'),
(4.42000007629395,  'john.doe'),
(1.33000004291534,  'john.doe'),
(0.579999983310699, 'john.doe'),
(3.29999995231628,  'john.doe'),
(2.1800000667572,   'john.doe'),
(0.620000004768372, 'john.doe'),
(0.25,  'john.doe')

select sum(hours) from #thisweek group by time_user
/* 40.0000002980232 */
/* Test: Nothing should come up since employee John Doe has 40 hours */
select sum(Round(hours,2)) hours /*<--- this is the same value as below*/, time_user

from

#thisweek

group by time_user
having sum(Round(hours,2)) < 40  /* how is 40 < 40? */
 select sum(Round(hours,2)) hours, time_user,  MAX(cdate) maxdate

    from

    #thisweek2

    group by time_user
    having  sum(Round(hours,2)) < 40.0
select convert(int,sum(Round(hours,2))) from #thisweek group by time_user
create table #thisweek (
    [hours] float,
    time_user varchar(100)
)
create table #thisweek (
    [hours] decimal(10, 4),
    time_user varchar(100)
)
select sum(hours) as hours, time_user
from #thisweek
group by time_user
having sum(hours) < 40;
select *
from
#thisweek2
where time_user = 1234

select hours , time_user
from
#thisweek2
where time_user = 1234

select hours, time_user,  MAX(cdate) maxdate
from
#thisweek2
where time_user = 1234
group by hours, time_user

select Round(hours,2) hours, time_user,  MAX(cdate) maxdate
from
#thisweek2
group by  Round(hours,2),time_user
having convert(int,sum(Round(hours,2))) < 40

select sum(Round(hours,2)) hours, time_user,  MAX(cdate) maxdate
from
#thisweek2
group by time_user
where time_user = 1234

select sum(Round(hours,2)) hours, time_user,  MAX(cdate) maxdate
from
#thisweek2
group by time_user
having sum(hours) < 40


select sum(Round(hours,2)) hours, time_user,  MAX(cdate) maxdate
from
#thisweek2
group by time_user
having sum(Round(hours,2)) < 40


select sum(Round(hours,2)) hours, time_user,  MAX(cdate) maxdate
from
#thisweek2
group by time_user
having convert(int,sum(Round(hours,2))) < 40
select sum(cast( hours * 100 + .5  as int) / 100.00) as hours, time_user
from #thisweek
group by time_user
having sum(hours) < 40
SELECT CONVERT(VARCHAR(100), SUM(ROUND(hours, 2)), 2) FROM #thisWeek