Re: A question of negative numbers..

2004-09-01 Thread Mikhail Entaltsev
abs()

- Original Message - 
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, September 01, 2004 12:59 PM
Subject: A question of negative numbers..


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?


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



RE: A question of negative numbers..

2004-09-01 Thread critters
Found answer to my own question:

Returns the absolute value of X: 

mysql SELECT ABS(2);
- 2
mysql SELECT ABS(-32);
- 32

This function is safe to use with BIGINT values.

MySQL Reference Manual (C) 2002 MySQL AB


Re: A question of negative numbers..

2004-09-01 Thread Alec . Cawley
[EMAIL PROTECTED] wrote on 01/09/2004 11:59:58:

 is there a function to make negative 
 numbers positive?

ABS(x)

See http://dev.mysql.com/doc/mysql/en/Mathematical_functions.html

Alec


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: A question of negative numbers..

2004-09-01 Thread Khazret Sapenov
ABS(column) ?

- Original Message - 
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, September 01, 2004 6:59 AM
Subject: A question of negative numbers..


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?


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: A question of negative numbers..

2004-09-01 Thread Michael Stassen
[EMAIL PROTECTED] 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
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]