Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add column values in mysql

Tags:

sql

mysql

logic

sum

This is my table data Student

enter image description here

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?

like image 912
Trialcoder Avatar asked Sep 12 '12 11:09

Trialcoder


People also ask

How do I add values to a specific column in MySQL?

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.

How can I add multiple values in one column in MySQL?

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.

Can we add column in MySQL table?

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.


1 Answers

Sum is a aggregate function. You dont need to use it. This is the simple query -

select *,(maths + chemistry + physics ) AS total FROM `student` 
like image 120
Piyu Avatar answered Oct 02 '22 14:10

Piyu