Jump to content

MySQL Column Addition


triphis

Recommended Posts

Arg, stuck again >.> How do I add all the values in a COLUMN. Example:

 

Name --- Age

Zach --- 17

Jake --- 16

Jim --- 12

 

So how would I go about adding all the values in the AGE column? Also, what column type should I use? I currently have INT, but is there anything better? the true use of this information will use used on a column with 8 digits (12345678). Thanx

Link to comment
Share on other sites

To add the ages

 

SELECT SUM(age) as total_age FROM mytable

 

From MySql manual :

 

the range of an INT column is -2147483648 to 2147483647. If you try to insert

-9999999999 into an INT column, the value is clipped to the lower endpoint of the range,

and -2147483648 is stored instead. Similarly, if you try to insert 9999999999, 2147483647

is stored instead.

If the INT column is UNSIGNED, the size of the column\'s range is the same but its endpoints

shift up to 0 and 4294967295. If you try to store -9999999999 and 9999999999, the values

stored in the column become 0 and 4294967296.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.