sql - MySQL SELECT function to sum current data -


I have a question that returns something like this:

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

But instead of that, I want something like this:

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

Is there a way to do this on the query (I am using MySQL)?

Tks

This is called cumulative amount.

There are Oracle and PostgreSQL , this is

calculated by using a window function: < In the MySQL , you can calculate it by using the session variable: / p>

  SELECT id, val, SUM () between (unsecured pricing and current row by ID ROES) Are: SET @ S = 0; SELECT id, val, @s: = @s + val ID to mytable ORDER;   

Or in a pure set-based but less efficient way:

  select t1.id, t1.val, SUM (t2.val) mytable 1 JOIN MEETABLE T2 ON T.ID & lt; = T.Ind Group by T.ID;    

Comments