Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 01-07-2010, 01:14 AM   #1 (permalink)
Apprentice
 
Join Date: Oct 2005
Location: Kolkatta
Posts: 86
Default Summation of Columns in SQL


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
__________________
Join My Mailing List at
http://groups.google.co.in/group/cooldev007smail
cooldev007 is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 01-07-2010, 10:10 AM   #2 (permalink)
Fullbring
 
Zangetsu's Avatar
 
Join Date: Jan 2008
Location: Soul Society
Posts: 5,523
Default Re: Summation of Columns in SQL

Quote:
Originally Posted by cooldev007 View Post
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....
__________________
I'm the One you've been Waiting for...
Zangetsu is offline   Reply With Quote
Old 01-07-2010, 11:11 AM   #3 (permalink)
Excessive happiness
 
furious_gamer's Avatar
 
Join Date: Jun 2008
Location: Bangalore
Posts: 2,974
Default Re: Summation of Columns in SQL

@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.
__________________
My First Android phone : Samsung Galaxy SL i9003 - Rooted & Gingerbread XXKPQ
Updated : superteekz_V2 ROM for XXKPQ.

PS Request
furious_gamer is offline   Reply With Quote
Old 01-07-2010, 11:50 AM   #4 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Summation of Columns in SQL

IMO, View is the ideal for this. Because it won't store total actually, but will calculate it when needed.
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline   Reply With Quote
Old 01-07-2010, 12:39 PM   #5 (permalink)
Excessive happiness
 
furious_gamer's Avatar
 
Join Date: Jun 2008
Location: Bangalore
Posts: 2,974
Default Re: Summation of Columns in SQL

^^



Can you elaborate this? I dont get you.
__________________
My First Android phone : Samsung Galaxy SL i9003 - Rooted & Gingerbread XXKPQ
Updated : superteekz_V2 ROM for XXKPQ.

PS Request
furious_gamer is offline   Reply With Quote
Old 01-07-2010, 02:04 PM   #6 (permalink)
Fullbring
 
Zangetsu's Avatar
 
Join Date: Jan 2008
Location: Soul Society
Posts: 5,523
Default Re: Summation of Columns in SQL

i got the solution:
just use default constraint on the table.....
no need of SP & trigger @ all
__________________
I'm the One you've been Waiting for...
Zangetsu is offline   Reply With Quote
Old 07-07-2010, 07:48 PM   #7 (permalink)
Apprentice
 
Join Date: Oct 2005
Location: Kolkatta
Posts: 86
Default Re: Summation of Columns in SQL

Thank To you all for your posts... How Can I Do this in Access 2007? Kindly Reply
__________________
Join My Mailing List at
http://groups.google.co.in/group/cooldev007smail
cooldev007 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Sql: copy values from one field to another in the same table phuchungbhutia Programming 1 19-03-2010 09:50 AM
Problem installing SQL Server 2000 coolazeem Software Q&A 4 10-02-2006 08:22 PM
distributing application developed using vb and sql server rajesh_nk22 QnA (read only) 1 07-02-2006 05:04 PM
PHP ODBC Connection failed , Sql Server 2000, help Butterfly QnA (read only) 5 03-10-2004 09:55 PM

 
Latest Threads
- by Charan
- by Charan
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 03:19 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2