在前台传入一个日期
如 2010年
后台输出
时间段在2010年的数据
时间段在2009年的数据
时间段在2008年的数据
时间段在2007年的数据
时间段在2006年的数据
也就是后面5年的时间段内的数据
如 2010年
后台输出
时间段在2010年的数据
时间段在2009年的数据
时间段在2008年的数据
时间段在2007年的数据
时间段在2006年的数据
也就是后面5年的时间段内的数据
declare @s varchar(100)
set @='2010'
select * from tb where datediff(yy,时间列,@s+'-01-01')<=5
--如果仅是输出数据,那就不是统计:
select * from tb where ltrim(year(时间))+'年'=传入的日期年份
set @date=2010select * from tb where datediff(year,[date],rtrim(@date)+'-01-01') between 1 and 5
set @yy='2010'
select * from tb where YEAR(时间列) BETWEEN @yy-4 AND @yy
select * from tb where dt between @dt and @dt - 5
select * from tb where @i-年份<=5