Ant-DAO-MentSmooth Charts
    Updated 2025-03-11
    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
    DAY_DATE
    BORROWED_AMOUNT
    REPAID_AMOUNT
    NET_BORROW
    1
    2021-10-01 00:00:00.000000
    2
    2021-10-02 00:00:00.000505
    3
    2021-10-03 00:00:00.000005
    4
    2021-10-04 00:00:00.000005
    5
    2021-10-05 00:00:00.0000-32
    6
    2021-10-06 00:00:00.0000-11
    7
    2021-10-07 00:00:00.000001
    7
    241B
    1s