tags:

views:

231

answers:

3

mysql table slalry:

aid    year    slalry
1      2000    1000
2      2001    2000
3      2002    3000
4      2003    4000

h

ow to get result as :

aid    year    slalry
1      2000    1000
2      2001    3000
3      2002    6000
4      2003    10000
+3  A: 

sql code:

   SELECT
        aid,year,
        salary=(SELECT SUM(slalry) FROM slalry WHERE year<=A.year)
    FROM slalry AS A;
ZA
+1  A: 

You can't get exactly the result you specify, as there will be no unique [aid] value for each year. However, omitting this column, you can use:

SELECT  year, SUM(slalry)
FROM    slalry
GROUP BY year
David M
A: 

Check out the information here.

Stack Overflow Question

Brian