我有一个表tblTimesheet,其中我存储用户计时hr。像这样
Hours
4.01
3.44
0.05
0.04
2.40
我想要的是我正在使用此
的部分时间段select sum(hours) from tbltimesheets where workDate='2012-08-30 00:00:00.000' and taskid in (86,3,34)
但它给了我9.94,我希望得到10.34这个字段的数据类型是十进制。
请帮帮我
提前致谢
答案 0 :(得分:1)
像
这样的东西DECLARE @Table TABLE(
Hrs FLOAT
)
INSERT INTO @Table SELECT 4.01
INSERT INTO @Table SELECT 3.44
INSERT INTO @Table SELECT 0.05
INSERT INTO @Table SELECT 0.04
INSERT INTO @Table SELECT 2.40
;WITH Vals AS (
SELECT SUM(FLOOR(Hrs)) NumHrs,
SUM((Hrs - FLOOR(Hrs)) * 100) NumMins
FROM @Table
)
SELECT NumHrs + FLOOR(NumMins / 60) + ((NumMins / 60 - FLOOR(NumMins / 60)) * 60 / 100)
FROM Vals
答案 1 :(得分:0)
first hours conet to minute and last step divide by 60.
select (sum(hours*60)/60) from tbltimesheets where workDate='2012-08-30 00:00:00.000' and taskid in (86,3,34)