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 2000 Forums
 Transact-SQL (2000)
 searching average balance

Author  Topic 

rezasyah
Starting Member

12 Posts

Posted - 2006-07-13 : 06:52:14
a FACT table contains these sample data :

FACT
------------------------------------------
DATE | ACCOUNT_NO | AMOUNT |
------------------------------------------
2/1/2006 | 080001 | 1000 |
2/1/2006 | 080002 | 500 |
2/1/2006 | 080003 | 5000 |
3/1/2006 | 080001 | 2000 |
3/1/2006 | 080002 | 1000 |
3/1/2006 | 080003 | 1500 |
4/1/2006 | 080001 | 2000 |
4/1/2006 | 080002 | 1000 |
4/1/2006 | 080003 | 1500 |
... | ... | ... |
31/1/2006| 080001 | 7000 |
31/1/2006| 080002 | 5000 |
31/1/2006| 080003 | 8000 |
------------------------------------------

i need a select statement to get this result :

--------------------------------------------------------------
MONTH_YEAR | ACCOUNT_NO | BALANCE_TYPE | AMOUNT |
--------------------------------------------------------------
JAN 2006 | 080001 |AVERAGE BALANCE | 5000 |
JAN 2006 | 080002 |AVERAGE BALANCE | 3500 |
JAN 2006 | 080003 |AVERAGE BALANCE | 4500 |
JAN 2006 | 080001 |END OF MONTH BALANCE | 7000 |
JAN 2006 | 080002 |END OF MONTH BALANCE | 5000 |
JAN 2006 | 080003 |END OF MONTH BALANCE | 8000 |
--------------------------------------------------------------

the formula to calculate Average Balance and End of Month Balance are :
- Average Balance is the sum of all the balances per month divided
by the number of days of the month
- End of Month Balance is the balance on the last day of the month

thanks before for all replies

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-13 : 06:55:09
Is this on MS Access or MS SQL Server ? Just to make sure


KH

Go to Top of Page

rezasyah
Starting Member

12 Posts

Posted - 2006-07-13 : 07:04:48
in MS SQL Server, im very grateful to khtan replies, thanks
Go to Top of Page
   

- Advertisement -