如何在postgresql的条件下获取累积(总和)的日期

How to get the date when accumulation (sum) in a condition in postgresql

我有 table 这样的:

id date total
123 2021-02-03 200000
123 2021-03-03 1650000
123 2021-02-04 1500000
123 2021-02-21 200000
123 2021-03-03 200000

如果我想获取总和达到 3000000 的日期或 2021-02-04 的日期,sql 查询如何?

预期输出是

id date total
123 2021-02-04 3350000

或者如果不可能的话可能是这样的:

id date
123 2021-02-04

使用这个

select top 1 * from (
select id,date,
SUM(total) OVER (ORDER BY date ROWS UNBOUNDED PRECEDING) as Total 
from tablename
)
where total >= 3000000