I work with a table (results) that has the following structure (do not ask, I did not create it)
id | record_type | user_id | answer_id | choice | score | total | email
-------------------------------------------------------------------------------
1 email xxxxxxx 0 userX@site.com
2 answer xxxxxxx aaaaaa A 0
3 answer xxxxxxx bbbbbb A 0
4 answer xxxxxxx cccccc B 10
5 email yyyyyyy 0 userY@site.com
6 answer yyyyyyy aaaaaa A 0
7 answer yyyyyyy bbbbbb A 0
8 answer yyyyyyy cccccc A 0
9 email zzzzzzz 0 userZ@site.com
10 answer zzzzzzz aaaaaa A 0
11 answer zzzzzzz bbbbbb A 0
12 answer zzzzzzz cccccc B 10
The results of the survey and the assessment of the correct answers changed after the polls were submitted. I already started the update to set the score for the “correct” answers to 10, and now I need to update the total number of lines using record_type: email so that we can contact the winners.
The goal would be to set the common column for rows 1.5 and 9 to 10.0 and 10
I think of something like this
UPDATE results SET total = SUM(score)
FROM results GROUP BY user_id WHERE user_id = user_id
But this does not look right, and I'm worried that maybe I'm wrong.
byron source
share