The statistical period is calculated ~ 1949-12-31,1950-1-1 ~ 1959-12-31 ,......) To classify statistics. The statements I wrote are as follows: Select Count (Strworkno) countper, yearfirst From (
Select Strworkno, ' Yearfirst ' = Case When Dtbirthday Between Cast (( Year (Dtbirthday) / 10 ) As Varchar ( 4 )) + ' 0-1-1 '
And Cast (( Year (Dtbirthday) / 10 ) As Varchar ( 4 )) + ' 9-12-31 ' Then Cast (( Year (Dtbirthday) / 10 ) As Varchar ( 4 )) + ' 0 '
Else ' 0 ' End
From Hremployee
)
Group By Yearfirst
Weekly Statistics
Select sum (sales amount), datename (Week, sales date-1) from sales where sales date between begindate and enddate group by datename (Week, sales date-1)
Note: here we need to set the sales date-1 because the first day of the week in SQL Server is Sunday by default, and the statistics we use are calculated from Monday to Sunday.