--建表加入数据
create table tt (日期 smalldatetime, 经济指标 int, 增长率 decimal null )
insert into tt values ('2010-1-1',1000,0)
insert into tt values ('2010-1-15', 2000, null)
insert into tt values ('2010-1-30', 3000, null)
insert into tt values ('2010-2-28', 5000, null)
insert into tt values ('2010-3-31', 5000, null)
insert into tt values ('2010-4-15', 4000, null)
--直接执行这个脚本就可以,他会直接显示出每期的增长率,负值为负增长
SELECT
t2.日期,t2.经济指标,CAST( (t2.经济指标 - t1.经济指标) AS DECIMAL(6,2))/t1.经济指标 AS 增长率
FROM (SELECT tt.日期,tt.经济指标,ROW_NUMBER() OVER(ORDER BY tt.日期)+1 AS num
FROM tt) AS t1
,(SELECT tt.日期,tt.经济指标,ROW_NUMBER() OVER(ORDER BY tt.日期) AS num FROM tt) AS t2
WHERE t1.num = t2.num