+ -
当前位置:首页 → 问答吧 → 求高手帮忙写一个按年统计的东西

求高手帮忙写一个按年统计的东西

时间:2011-11-28

来源:互联网

在前台传入一个日期
如 2010年
后台输出
时间段在2010年的数据 
时间段在2009年的数据 
时间段在2008年的数据 
时间段在2007年的数据 
时间段在2006年的数据 
也就是后面5年的时间段内的数据

作者: mingming8915   发布时间: 2011-11-28

SQL code

declare @s varchar(100)
set @='2010'
select * from tb where datediff(yy,时间列,@s+'-01-01')<=5

作者: fredrickhu   发布时间: 2011-11-28

SQL code

--如果仅是输出数据,那就不是统计:
select * from tb where ltrim(year(时间))+''=传入的日期年份


作者: qianjin036a   发布时间: 2011-11-28

declare @date int
set @date=2010

select * from tb where datediff(year,[date],rtrim(@date)+'-01-01') between 1 and 5

作者: ssp2009   发布时间: 2011-11-28