下面的查询对我来说很好,但是我想要的是,如果so_far类似于297,下一个some_num_field为4,则查询将返回记录,总计为297。在这种情况下,它应该获得下一行由created_at的some_num_field值小于<= 3(300-297)
的订单WITH eligible as (
select id, name, some_num_field,
sum(some_num_field) over (ORDER BY created_at) as so_far
from test
)
SELECT *
FROM eligible
WHERE so_far <= 300