List:General Discussion« Previous MessageNext Message »
From:Michael Stassen Date:September 1 2004 3:12pm
Subject:Re: A question of negative numbers..
View as plain text  
critters@stripped wrote:
> Hi,
> I have a query that returns a list of numbers ranging from -10 to +10
> I would like to be able to have a 2nd column where a result of 5 is 5
> but -5 is also 5, so in effect all the negative (and only the negative)
> results are made positive to find the deviation from zero.
> so 5, 4, -3, 4, -1, 0
> would become 5, 4, 3, 4, 1, 0
> I have been searching for if then else in google so I could do if a < 0
> then a = 0-a but no joy. is there a function to make negative numbers
> positive?

You've already discovered ABS(), the absolute value function, which is the 
correct solution.  I just wanted to point out that mysql does have an IF() 
function, as well, since you didn't find it.  For example, you could 
accomplish the same thing with

   IF(a >= 0, a, -a)

IF() is documented in the manual 
<>.  I'd 
suggest trying the manual first, rather than Google, when looking for mysql 

A question of negative numbers..critters1 Sep
  • Re: A question of negative numbers..Mikhail Entaltsev1 Sep
  • Re: A question of negative numbers..Alec.Cawley1 Sep
  • Re: A question of negative numbers..Khazret Sapenov1 Sep
  • Re: A question of negative numbers..Michael Stassen1 Sep
RE: A question of negative numbers..critters1 Sep