MySQL query that computes partial sums

前端 未结 2 1039
礼貌的吻别
礼貌的吻别 2021-01-14 19:32

What query should I execute in MySQL database to get a result containing partial sums of source table?

For example when I have table:

Id|Val
1 | 1
2         


        
2条回答
  •  心在旅途
    2021-01-14 20:01

    SELECT l.Id, SUM(r.Val) AS Val
    FROM your_table AS l
        INNER JOIN your_table AS r
            ON l.Val >= r.Val
    GROUP BY l.Id
    ORDER By l.Id
    

提交回复
热议问题