MySQL SELECT function to sum current data

后端 未结 3 401
醉酒成梦
醉酒成梦 2020-12-21 12:11

I have a query that return something like this:

| ID | Val |  
| 0  | 10  |     
| 1  | 20  |     
| 2  | 30  |  

But instead of that, I wa

3条回答
  •  没有蜡笔的小新
    2020-12-21 12:52

    Assuming the table name is t, you can use a query like this:

    select t.id, t.val, sum(t2.val) Sum
      from t, t t2
     where t2.id <= t.id
    group by t.id, t.val
    

    (tested in Oracle)

提交回复
热议问题