我在 Excel 中有一个公式可以计算两个日期之间有多少个星期天,但我想在 SQL 中做同样的事情,但不知道该怎么做。你能帮我吗?
=SUM(INT((WEEKDAY(A1-8,1)+B1-A1)/7))
Declare @From as Datetime
Declare @To as Datetime
Set @From = '7 Jan 2013'
Set @To = '18 Mar 2013'
SELECT SUM(WEEKDATE(@From-8,1)+ @End-@From)/7)) AS No_Of_Sundays
FROM TIME
谢谢
韦恩