DIGIT-ARC read-only archive · snapshot: July 23, 2026

Summation of Columns in SQL

7 posts · originally from https://geek.digit.in/community/threads/summation-of-columns-in-sql.128915/

C
cooldev007 Original post #1
Jul 1, 2010 at 1:14 AM
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
Jul 1, 2010 at 10:10 AM
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
Jul 1, 2010 at 11:11 AM
@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
Garbage #4
Jul 1, 2010 at 11:50 AM
IMO, View is the ideal for this. Because it won't store total actually, but will calculate it when needed.
furious_gamer
Jul 1, 2010 at 12:39 PM
^^

:neutral:

Can you elaborate this? I dont get you.
Zangetsu
Jul 1, 2010 at 2:04 PM
i got the solution:
just use default constraint on the table.....
:grin: no need of SP & trigger @ all
C
Jul 7, 2010 at 7:48 PM
Thank To you all for your posts... How Can I Do this in Access 2007? Kindly Reply