试试这个——
DECLARE
@FirstDayOfWeek DATETIME
, @LastDayOfWeek DATETIME
SELECT
@FirstDayOfWeek = DATEADD(wk, DATEDIFF(wk, 6, GETDATE()), 6)
, @LastDayOfWeek = DATEADD(wk, DATEDIFF(wk, 5, GETDATE()), 5)
SELECT
INTERVIEW_COUNT_DAY = COUNT(INTERVIEW_ID)
, DATEPART(weekday, DATE_TIME)
FROM dbo.Interviews i
JOIN dbo.CVsSent cvt ON i.CVSENT_ID = cvt.CVSENT_ID
WHERE cvt.EMP_ID = e.EMP_ID
AND (i.DATE_TIME >= @FirstDayOfWeek AND i.DATE_TIME < @LastDayOfWeek)
GROUP BY DATEPART(weekday, DATE_TIME)
更新:
DECLARE @PrevWeek DATETIME = DATEADD(DAY, -7, GETDATE())
DECLARE
@FirstDayOfPrevWeek DATETIME = DATEADD(wk, DATEDIFF(wk, 6, @PrevWeek), 6)
, @LastDayOfPrevWeek DATETIME = DATEADD(wk, DATEDIFF(wk, 5, @PrevWeek), 5)
SELECT @FirstDayOfPrevWeek, @LastDayOfPrevWeek