Jump to content

[SOLVED] whats the deal with sum and negative numbers


emehrkay

Recommended Posts

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

;

 

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

Archived

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

×
×
  • 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.