鉴于时间框架,我能够计算最低平衡的最佳方法是什么? 在我的数据库中,我有一个交存栏和一份撤销栏和日期栏。
<><>><>>Update<>>>>>
假设1/1,余额为300。 1/2时,共交存300份。 1/15, 200美元被撤回,余额为400美元。 1/25年,又撤回300份,余额减至100份。 1/28,800个交存,余额共计900个。 如果在1/31时我计算该月的最低余额,我就应当得到100。 任何想法?
鉴于时间框架,我能够计算最低平衡的最佳方法是什么? 在我的数据库中,我有一个交存栏和一份撤销栏和日期栏。
<><>><>>Update<>>>>>
假设1/1,余额为300。 1/2时,共交存300份。 1/15, 200美元被撤回,余额为400美元。 1/25年,又撤回300份,余额减至100份。 1/28,800个交存,余额共计900个。 如果在1/31时我计算该月的最低余额,我就应当得到100。 任何想法?
使用窗户功能来建立运行平衡,然后在每一时间间隔期间提取最低功能:
with cte_transaction_data as
(
select 300 as deposit, null as withdraw, date 01/02/2010 as transaction_date union all
select null, 200, date 01/15/2010 union all
select null, 300, date 01/25/2010 union all
select 800, null, date 01/28/2010
)
select
month,
min(balance) as minimum_balance
from
(
select
transaction_date,
date_trunc( month , transaction_date) as month,
300
+ coalesce(sum(deposit) over(order by transaction_date rows between unbounded preceding and current row), 0)
- coalesce(sum(withdraw) over(order by transaction_date rows between unbounded preceding and current row), 0) as balance
from cte_transaction_data
) as running_balance
group by
month
order by
month
结果:
month minimum_balance
2010-01-01 00:00:00-06 100
Loop through each entry in the database for every day that there was a deposit/withdrawal and store the lowest number in a variable. If the number for the day being checked is lower, replace the variable with that number.
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...