Jump to content

Archived

This topic is now archived and is closed to further replies.

triphis

MySQL Column Addition

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Now there\'s one I didn\'t know! Thanks for the info!

 

(Betcha I still get it wrong when it comes time to use it though!)

 

D

Share this post


Link to post
Share on other sites

×

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.