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


    QueryRunArchived: QueryRun has been archived