Я использую SQL Server 2012 и есть заявление, которое возвращает эти записи для текущей недели:SQL Server: DateDiff с прошлой неделей
Employee , Sun , Mon , Tues, Wed, Thurs, Fri, Sat
--------------------------------------------------
Smith 5 8 5 4 8 4 0
Burt 7 1 8 5 4 4 7
Это мой SQL и неделя начинается на Солнце Как мне изменить, чтобы он показывал предыдущую неделю?
SELECT
ReproofMidLineBy AS Employee,
COUNT(CASE WHEN DATENAME(dw, ReproofMidLineDate)= 'Sunday' THEN 1 END) AS Sun,
COUNT(CASE WHEN DATENAME(dw, ReproofMidLineDate)= 'Monday' THEN 1 END) AS Mon,
COUNT(CASE WHEN DATENAME(dw, ReproofMidLineDate)= 'Tuesday' THEN 1 END) AS Tues,
COUNT(CASE WHEN DATENAME(dw, ReproofMidLineDate)= 'Wednesday' THEN 1 END) AS Wed,
COUNT(CASE WHEN DATENAME(dw, ReproofMidLineDate)= 'Thursday' THEN 1 END) AS Thurs,
COUNT(CASE WHEN DATENAME(dw, ReproofMidLineDate)= 'Friday' THEN 1 END) AS Fri,
COUNT(CASE WHEN DATENAME(dw, ReproofMidLineDate)= 'Saturday' THEN 1 END) AS Sat,
COUNT(*) AS TOTAL
FROM
dbo.tblJobLog
WHERE
(ReproofMidLineDate BETWEEN DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE())/7 * 7, 0)
AND DATEADD(DAY, DATEDIFF(DAY, 6, GETDATE()- 1)/7 * 7 + 7, 6)
)
GROUP BY
ReproofMidLineBy
сортируют, спасибо! – Michael