Summation of Columns in SQL

cooldev007

Broken In
Suppose I have 3 columns of 3 different subjects say History, Maths and Science. Now I want to add the total of their values to another column say Total. Is it possible in MySQL? Is there any function for doing this. Also MySQL should automatically update the values when its data is stored in 3 columns of 3 different subjects. For e.g., Somebody has entered History Marks and another has entered Maths Marks. Then MySQL should automatically calculate the sum of History and Maths and keep the total even though the value of Science has not been entered. How this can be done with PHP and MySQL? Please Help
 

Zangetsu

I am the master of my Fate.
Suppose I have 3 columns of 3 different subjects say History, Maths and Science. Now I want to add the total of their values to another column say Total. Is it possible in MySQL? Is there any function for doing this. Also MySQL should automatically update the values when its data is stored in 3 columns of 3 different subjects. For e.g., Somebody has entered History Marks and another has entered Maths Marks. Then MySQL should automatically calculate the sum of History and Maths and keep the total even though the value of Science has not been entered. How this can be done with PHP and MySQL? Please Help

i dont abt MySQL but in SQL u can create a trigger for the requirement u have....:-o
 

furious_gamer

Excessive happiness
@OP

Nope, MySQL doesn't do this. You have to write a trigger or a Stored Procedure to achieve this.

Just learn trigger and SP and this task is very easy as it sounds, trust me.
 

Garbage

God of Mistakes...
IMO, View is the ideal for this. Because it won't store total actually, but will calculate it when needed.
 
Top Bottom