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.
| Author |
Topic |
|
miles away
Starting Member
1 Post |
Posted - 2010-12-14 : 04:41:18
|
| Hi there,I'm hoping to get some assistance on an SQL statement that would calculate a year by year percentage change. The data is residing in the database in the format below;Code year number1 2005 20.22 2006 253 2007 38.64 2008 61.8I would like the statement to calculate the year by year percentage change similar to the example below;Year 2005 2006 2007 2008number 20.2 25 38.6 61.8% Change 23.76% 54.40% 60.10% Any suggestions would be greatly appreciated |
|
|
Devart
Posting Yak Master
102 Posts |
Posted - 2010-12-14 : 05:40:21
|
| Hello,For example:SELECT t1.year, t1.number, cast(100*(t1.number-t2.number)/t2.number as decimal(18,2)) AS changeFROM <your_table_name> t1 LEFT JOIN <your_table_name> t2 ON t1.year=t2.year+1Devart,SQL Server Tools:dbForge Schema ComparedbForge Data ComparedbForge Query Builder |
 |
|
|
|
|
|