Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Calculate Growth Rate using SQL Query

Author  Topic 

khushi2005
Starting Member

2 Posts

Posted - 2009-03-03 : 08:52:37
Is there a way to calculate year to year growth rates using SQL query

I am trying to use SQL Reporting Services and MAtrix control in that
It is very difficult to add a growth rate columns after ther Matrix
Hence I thught maybe I can calculate Growth Rate column and then have another Matrix which will display this Growth Rate


I know it should a self join on tables I am using but somehow my first year is getting skipped

select d.id,d.year,d.Val ,d.Val- d1.Val
from table1 d
join table1 d1 on d1.id=d.id and d.year-1=d1.year


Thanks in advance

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-03 : 09:00:37
post sample data and output.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-03 : 09:00:41
[code]select d.id,d.year,d.Val ,d.Val- coalesce(d1.Val,0)
from table1 d
outer apply (select sum(Val) AS Val
from table1
where id=d.id
and d.year-1=year
)d1
[/code]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-03 : 09:01:59
See http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -