DAY_DATE | BORROWED_AMOUNT | REPAID_AMOUNT | NET_BORROW | |
---|---|---|---|---|
1 | 2021-10-01 00:00:00.000 | 0 | 0 | 0 |
2 | 2021-10-02 00:00:00.000 | 5 | 0 | 5 |
3 | 2021-10-03 00:00:00.000 | 0 | 0 | 5 |
4 | 2021-10-04 00:00:00.000 | 0 | 0 | 5 |
5 | 2021-10-05 00:00:00.000 | 0 | -3 | 2 |
6 | 2021-10-06 00:00:00.000 | 0 | -1 | 1 |
7 | 2021-10-07 00:00:00.000 | 0 | 0 | 1 |
Ant-DAO-MentSmooth Charts
Updated 2025-03-11
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
›
⌄
WITH
raw_data as (
select '2021-10-02' as day_date, 5 as borrow, null as repay
union select '2021-10-05' as day_date, null as borrow, -3 as repay
union select '2021-10-06' as day_date, null as borrow, -1 as repay
),
dates as (
select
-- first argument is unit of time to add, second is amount to increment, third is starting date
dateadd(day, '+' || row_number() over (order by null), '2021-10-01'::date - 1) as day_date
from table (generator(rowcount => 7))
)
select
d.day_date,
nvl(r.borrow,0) as borrowed_amount,
nvl(r.repay,0) as repaid_amount,
sum(borrowed_amount + repaid_amount) over (order by d.day_date) as net_borrow
from dates d
left join raw_data r on d.day_date = r.day_date
Last run: about 1 month ago
7
241B
1s