This is my table data Student
And this is my query --
SELECT id, SUM( maths + chemistry + physics ) AS total, maths, chemistry, physics FROM `student`
but it is throwing a single row --
id total maths chemistry physics 118 760 55 67 55
although i want to apply sum for all ids ....let me know how can i achieve this?
First, you must specify the name of the table. After that, in parenthesis, you must specify the column name of the table, and columns must be separated by a comma. The values that you want to insert must be inside the parenthesis, and it must be followed by the VALUES clause.
First, specify the name of table that you want to insert after the INSERT INTO keywords. Second, specify a comma-separated column list inside parentheses after the table name. Third, specify a comma-separated list of row data in the VALUES clause.
To add a column in a table in MySQL, we can use ALTER command with add column command. First, let us create a table with columns Id and Name. After that, we will add column name Age and Address with the help of ALTER command.
Sum is a aggregate function. You dont need to use it. This is the simple query -
select *,(maths + chemistry + physics ) AS total FROM `student`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With