| Author |
Topic |
|
dewacorp.alliances
452 Posts |
Posted - 2006-07-11 : 21:30:20
|
| Hi there I got this following table:FinancialMonth, FinancialYear, BudgetAmount1, 2005, 102, 2005, 153, 2005, 204, 2005, 255, 2005, 306, 2005, 357, 2005, 408, 2005, 459, 2005, 5010, 2005, 5511, 2005, 6012, 2005, 651, 2006, 52, 2006, 10I want to add another column that called YTDBuddgetAmount which have the following condition:IF FinancialMonth = 1 then get the SUM of BudgetAmount OF FinancialMonth IN (1) FOR SPECIFIC YEARIF FinancialMonth = 2 then get the SUM of BudgetAMount OF FinancialMonth IN (1, 2) FOR SPECIFIC YEARSo basically, it will have like this:FinancialMonth, FinancialYear, BudgetAmount, YTDBUdgetAmount1, 2005, 10, 102, 2005, 15, 253, 2005, 20, 45...1, 2006, 5, 52, 2006, 10, 15I'm trying to use case and no luck.I'm appreciated your help.Thanks |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2006-07-11 : 21:58:48
|
Simple grouping should do it:select FinancialYear, FinancialMonth, (select sum(BudgetAmount) from table1 where FinancialYear=a.FinancialYear and FinancialMonth<=a.FinancialMonth)from table1 a |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-07-11 : 23:34:45
|
Why don't you perform the cumulative function in your front end application ? KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-12 : 02:12:11
|
| Where do you want to show data?If you use Reports, then make use of Running Total featureMadhivananFailing to plan is Planning to fail |
 |
|
|
dewacorp.alliances
452 Posts |
Posted - 2006-07-13 : 02:32:00
|
quote: Originally posted by timmy Simple grouping should do it:select FinancialYear, FinancialMonth, (select sum(BudgetAmount) from table1 where FinancialYear=a.FinancialYear and FinancialMonth<=a.FinancialMonth)from table1 a
Thanks for that. Now I got another issue which is FinanceMonth has an extra value which is 0 and 13. The business rule is ignore 0. For 13, make it as null as well but add BudgetAmount of 13 into FinancialMonth 12.I've done the modification of your quiry by adding and FinanceMonth >= 1 to cater the 0 thingy but not sure how to handle the FinanceMonth - 13 one.select FinancialYear, FinanceMonth, BudgetAmount, (select sum(BudgetAmount) from test b where b.FinancialYear = a.FinancialYear and b.FinanceMonth <= a.FinanceMonth and FinanceMonth >= 1) AS YTDBudgetAmountfrom test aORDER BY FinancialYear, FInanceMonthThanks |
 |
|
|
dewacorp.alliances
452 Posts |
Posted - 2006-07-13 : 02:34:04
|
quote: Originally posted by madhivanan Where do you want to show data?If you use Reports, then make use of Running Total featureMadhivananFailing to plan is Planning to fail
It needs to be done in table level which is the query it's all about due the app is lack of feature that you mentioned: Running Total feature. |
 |
|
|
|
|
|