Mc Gyver Basaya Mc Gyver Basaya - 3 months ago 5
MySQL Question

add column value from a 1 row of a table and display the other column

I want to add a multiple column and display the other column. Here is my database table:

ID | firstname | lastname | score1 | score2 | score3
1 | mark | lupez | 5 | 7 | 4
2 | james | cruz | 6 | 3 | 5


I want to add score1, score2 and score3 in every row and display like this:

ID | lastname | firsname | total_score |
1 | mark | lupez | 16 |
2 | james | cruz | 14 |


I try to google and find the answer but no luck, my mind is not working though.

Answer

Just add the score columns:

SELECT ID,
       firstname,
       lastname,
       score1 + score2 + score3 AS total_score
FROM yourTable
Comments