我想把工作总时数加起来并按周分组。我的星期一星期一开始,星期天结束我遇到的问题是这些数字总是在第一周,但其余的几周都很好。第一周的问题总是非常低。
查看快照
这是我的代码
SELECT
UID,
CONVERT(VARCHAR, x.WeekBeginDate, 101) as WeekBeginDate,
x.TOTAL_HOURS
FROM
(SELECT
UID,
DATEADD(DD, CONVERT(INT, (DATEDIFF(DD, '1/1/1900', t.DT)/7)) * 7, '1/1/1900') [WeekBeginDate],
SUM(HOURS) AS TOTAL_HOURS
FROM
myTable t
WHERE
UID = 'test1'
AND DT >= DATEADD(WEEK, -6, GetDate())
GROUP BY
UID, CONVERT(INT, DATEDIFF(DD, '1/1/1900', t.DT)/7) ) x
ORDER BY
1