Stevan Dejanovic
Stevan Dejanovic

Reputation: 13

Summing in mysql previous row with current

Need help to make query. I have table like this:

kli, akt, mes

'2', '2',  '201209'

'2', '2',  '201210'

'3', '3',  '201211'

And I need a result table:

kli, akt, mes

'2', '2',  '201209'

'4', '4',  '201210'

'7', '7',  '201211'

result tables sum by field mes, current and all previous rows

Upvotes: 0

Views: 72

Answers (1)

Praveen E
Praveen E

Reputation: 976

try the below query

SELECT SUM(b.kli),SUM(b.akt),a.mes FROM tableName a INNER JOIN tableName b ON a.mes >= b.mes GROUP BY a.mes

Upvotes: 1

Related Questions