MYSQL adding columns value of rows

I have a problem in which I have a STUDENT table as

+-------------+-------------+-------------+-------------+---------------+
| roll_number | name        | subject_one | subject_two | subject_three |
+-------------+-------------+-------------+-------------+---------------+
|           1 |  Sheila     |          32 |          48 |            64 |
|           2 | Rachel      |          24 |          21 |            25 |
|           3 | Christopher |          55 |          12 |            10 |
+-------------+-------------+-------------+-------------+---------------+

I want the print the output as

+-------------+-------------+-------------+
| roll_number | name        | total       | 
+-------------+-------------+-------------+
|           1 |  Sheila     |          144|
|           2 | Rachel      |          70 |     
|           3 | Christopher |          77 |
+-------------+-------------+-------------+

and select all student having marks greater than 75 ??
How can I achieve this using MYSQL ??

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I think you just need the aggregate functions and using them is enough. I am not sure if it can help you or not.

SELECT roll_number , name , (subject_one + subject_two + subject_three) AS total FROM STUDENT HAVING total > 75 ;


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x