我写了一个查询,但没有给出正确的答案。我想这样显示
5小时58分钟+7小时58分钟= 13小时56分钟(答案应13.56
),但下面的查询给出了15.09
。
请使用任何其他解决方案回复我。(此处Effort1
为5小时栏,Effort1Minutes
为58分钟栏,同一Effort2
为7小时栏,Effort2Minutes
为58分钟专栏。
select CAST((SUM(Effort1)*60+SUM(Effort1Minutes))/60 as float) +
(CAST((SUM(Effort1)*60+SUM(Effort1Minutes))% 60 as float)) / 100 +
CAST((SUM(Effort2)*60+SUM(Effort2Minutes))/60 as float) +
(CAST((SUM(Effort2)*60+SUM(Effort2Minutes))% 60 as float)) / 100
from TimesheetDetails
答案 0 :(得分:1)
请尝试以下查询
select CONVERT(decimal(18,2),SUM(Effort1 + Effort2)) +
SUM(Effort1Minutes + Effort2Minutes) / 60 +
CONVERT(decimal(18,2), (SUM(Effort1Minutes + Effort2Minutes) % 60) / 100.00)
from TimesheetDetails
我已经使用SQL Server 2008以及SQL Fiddle
对此查询进行了测试