我想從上週五12PM到本週五12PM提交所有記錄提交給SQL Server用於工資單。我有7天的工作時間,如下圖所示,但我需要的是上週五的12PM到本週五的12PM。SQL Server:SELECT上週五下午12點到這個星期五12 PM
SELECT DISTINCT
notifications.requestid,
Max(timestatuschange),
assignedtouser,
Count(requestid) AS Total
FROM
notifications
WHERE
timestatuschange >= Dateadd(day, -7, Getdate())
AND notifications.status = 'Yellow'
OR timestatuschange >= Dateadd(day, -7, Getdate())
AND notifications.status = 'Red'
OR timestatuschange >= Dateadd(day, -7, Getdate())
AND notifications.status = 'Blue'
GROUP BY
requestid,
assignedtouser
的SQL Server版本是你使用? – ughai
Azure SQL Server –
請定義上星期五和這個星期五。通過這個星期五,你的意思是今天如果是星期五和未來的一些點,如果不是星期五? – Hogan