Friday, 15 May 2015

MySQL SUM cells with same ID and insert it in table -


Please help me with that: I have this table:

 id key value 1 word 1 35 1 term 2 1 word 3 40 2 word 1 12 2 word 2 2 words 3 11 3 word 1 51 3 word 2 3 word 3 23 

In every id Key column Term2 which is the sum of word1 and Term3 . And that amount should be entered in the value column. In this way:

 Value of ID Key 1 word 1 35 1 Term 2 75 1 Term 3 40 2 Term 1 12 2 Term 2 23 2 Term 3 11 3 Term 1 51 3 Term 2 743 Term 3 23 

Thanks!

If you want to update the table, use join :

  Add the update table to T (add value id to sum as yoga (id 'by' '1', 'term3') key in the group) T.id = tt.id TT set T.value = tt.sumvalue where t.key = 'term1';  

Note that the key is a keyword in MySQL (and in general SQL). I keep the name, because in this way the question is a question.


No comments:

Post a Comment