我希望我一周的第一天是星期日,但我的代码问题是它总是从星期一开始.
I want my first day of the week to be as Sunday but my issue with my code is that it starts always as Monday.
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
DT >= DATEADD(WEEK, -6, GetDate())
GROUP BY
UID, CONVERT(INT, DATEDIFF(DD, '1/1/1900', t.DT)/7)
这应该可以解决问题:
SELECT
UID,
DATEADD(d, -1, DATEDIFF(d, -1, t.DT)/7 * 7) [WeekBeginDate] ,
SUM(HOURS) AS TOTAL_HOURS
FROM myTable t
WHERE DT >= DATEADD(WEEK, -6, GetDate())
GROUP BY UID, DATEDIFF(d, -1, t.DT)/7
这篇关于在 SQL 中将一周的第一天作为星期日开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!