emehrkay Posted November 12, 2007 Share Posted November 12, 2007 What do I use to get it to work with negative numbers? Link to comment https://forums.phpfreaks.com/topic/76934-solved-whats-the-deal-with-sum-and-negative-numbers/ Share on other sites More sharing options...
toplay Posted November 12, 2007 Share Posted November 12, 2007 I suggest you be more clear and show code/SQL so people better understand what your problem is. MySQL sum() function does handle negative numbers. So, why do you think it doesn't? Examples: select sum(number) # You get correct answer of -3 from (select -1 AS number union select -2 AS number ) test ; select sum(number) # You get correct answer of zero (-1 + 1 = 0) from (select -1 AS number union select 1 AS number ) test ; Link to comment https://forums.phpfreaks.com/topic/76934-solved-whats-the-deal-with-sum-and-negative-numbers/#findComment-389944 Share on other sites More sharing options...
emehrkay Posted November 12, 2007 Author Share Posted November 12, 2007 Im sorry about my vague post, I was on an hour-long stint with trying to get sum to work with a -1. The problem was that i was inputting the -1 manually in the db with query browser and I guess it was registering as a negative number. I then wrote a simple insert using -1 and it worked fine. Thanks for the help Link to comment https://forums.phpfreaks.com/topic/76934-solved-whats-the-deal-with-sum-and-negative-numbers/#findComment-389952 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.