MYSQL - How to increment fields in one row with values from another row
Posted
by
Walker Boh
on Stack Overflow
See other posts from Stack Overflow
or by Walker Boh
Published on 2013-06-24T16:09:57Z
Indexed on
2013/06/24
16:21 UTC
Read the original article
Hit count: 238
I have a table that we'll call 'Sales' with 4 rows: uid, date, count and amount. I want to increment the count and amount values for one row with the count/amount values from a different row in that table. Example:
UID | Date | Count | Amount|
1 | 2013-06-20 | 1 | 500 |
2 | 2013-06-24 | 2 | 1000 |
Ideal results would be uid 2's count/amount values being incremented by uid 1's values:
UID | Date | Count | Amount|
1 | 2013-06-20 | 1 | 500 |
2 | 2013-06-24 | 3 | 1500 |
Please note that my company's database is an older version of MYSQL (3.something) so subqueries are not possible. I am curious to know if this is possible outside of doing an "update sales set count = count + 1" and likewise for the amount columns. I have a lot of rows to update and incrementing the values individually is quite time consuming if you can imagine. Thanks for any help or suggestions!
© Stack Overflow or respective owner