I have sample data with table name catdog
| No | id | data |
1 1 4000
2 2 300
3 3 100
4 1 400
5 2 30
6 3 10
7 1 40
8 2 3
9 3 1
I want the result like this:
| No | id | data | totaldata |
1 1 4000 4000
2 2 300 300
3 3 100 100
4 1 400 4400 --------> 4000 + 400 on id
5 2 30 330 --------> 300 + 30 on id
6 3 10 110 --------> 100 + 10 on id
7 1 40 4440 --------> 4000 + 400 + 40 on id
8 2 3 333 --------> 300 + 30 + 1 on id
9 3 1 111 --------> 100 + 10 + 1 on id
Sum if field No is same. How to write a mysql query for my case?
very very thank you so much GurV