Jump to content

[SOLVED] whats the deal with sum and negative numbers


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

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.