my question is
how to sum and auto-increment into other column when we insert into column 1
| id | Column1(Inserted) | column2(Auto-increment column) |
| 1 | 10 | 10 |
| 2 | 10 | 20 |
| 3 | 20 | 40 |
| 4 | 30 | 70 |
how to perform this and what is the query for this kind of result
| id | Column1(Inserted) | column2(Auto-increment column) |
| 1 | 10 | 10 |
| 2 | 10 | 20 |
| 3 | 20 | 40 |
| 4 | 30 | 70 |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Midhun TpRank #388 · 6.5K reputationPosted Apr 3, 2017, 1:21 AM EDT
SET @val=10
INSERT INTO tablename (col1, col2)
SELECT @val,isnull(sum(col1),0)+@val FROM tablename
Ramesh PalanivelRank #372 · 6.8K reputationPosted Mar 30, 2017, 4:18 AM EDT
Jitendra ShekhawatRank #1,909 · 772 reputationPosted Mar 30, 2017, 4:40 AM EDT
Manish KumarRank #1,622 · 956 reputationPosted Apr 2, 2017, 11:28 PM EDT
Nitin SontakkeRank #264 · 9.6K reputationPosted Apr 2, 2017, 11:41 PM EDT