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
<http://dev.mysql.com/doc/mysql/en/Control_flow_functions.html>. I'd
suggest trying the manual first, rather than Google, when looking for mysql
functions.
Michael