PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Postgresql seleciona até que determinado valor total seja alcançado

select id, 
       date, 
       amount, 
       running_total
from (
    select id,
           date,
           amount,
           sum(amount) over (order by date asc) as running_total
    from transactions
) t
where running_total <= 6