SQL Server中是否有一种方法可以从具有日期列(1998到2010)的表中显示会计年度(从10月1日开始到9月30日结束).这是我做的:
select 'FY1999' as FY, site, count(*)
from mytable
where mydate >='10/1/1998'
and mydate <'10/1/1999'
group by site
Run Code Online (Sandbox Code Playgroud)
select 'FY2000' as FY, site, count(*)
from mytable
where mydate >='10/1/1999'
and mydate <'10/1/2000'
group by site
Run Code Online (Sandbox Code Playgroud)
select 'FY2001' as FY, site, count(*)
from mytable
where mydate >='10/1/2000'
and mydate <'10/1/2001'
group by site
Run Code Online (Sandbox Code Playgroud)
这个年度超过10年这样做是不是太重复了?