Jump to content


Photo

MySQL Column Addition


  • Please log in to reply
3 replies to this topic

#1 triphis

triphis
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 29 September 2003 - 02:58 PM

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
Xac Attack

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,019 posts

Posted 29 September 2003 - 06:18 PM

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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 pauper_i

pauper_i
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts
  • LocationPhoenix, AZ, USA

Posted 29 September 2003 - 06:43 PM

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
Genius is one percent inspiration, and ninety-nine percent perspiration. [br]Thomas Alva Edison

#4 triphis

triphis
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 29 September 2003 - 08:35 PM

Wow! Thank you Barand :P You are always a huge help!
Xac Attack




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users