Sum of multiple columns values in a row

With help of the following simple query you can find sum of multiple columns values in a row.

In the marks table below we have roll number and marks of each student in physics, chemistry and maths. Now we wish to find sum of marks obtained by each student.

rollnophysicschemistrymaths
1293150
2526972
3333570
4474193
5524894
6846465
7938345
8552791
9663531
10894499
11622894
12298689
13469360
14597766
15778583

The query and output will be:

rollnototal
1110
2193
3138
4181
5194
6213
7221
8173
9132
10232
11184
12204
13199
14202
15245

If you wish to get sum of multiple columns values in all rows or sum of marks of all students in all subjects, then

total
2821

And to obtain all rows from marks table with an extra column as sum of multiple columns values in that row as total:

rollnophysicschemistrymathstotal
1293150110
2526972193
3333570138
4474193181
5524894194
6846465213
7938345221
8552791173
9663531132
10894499232
11622894184
12298689204
13469360199
14597766202
15778583245

You Might Interested In

Leave a Reply

Enclose a code block like: <pre><code>Your Code Snippet</code></pre>.