Forum Moderators: coopster

Message Too Old, No Replies

Math functions in SQL statement

         

ironik

11:27 pm on Jun 27, 2005 (gmt 0)

10+ Year Member



I'm trying to create a SELECT order based on several database fields...

SELECT * FROM myTable WHERE 1 ORDER BY field1 DESC, field2 DESC, field3 DESC

The thing is, I don't want to order it preferentially by one, then the other, then another.

I'm not 100% familiar with the math functions in an SQL statement, but is there anyway I can sum the values of all fields into a single value, and then create an order off that value? ... I'm thinking something similar to CONCAT for aggregating text and field values, but mathematical.

I don't want a SUM of all values, but rather a SUM for the field values in individual rows... can't figure this one out...

Thanks in advance

coopster

1:04 am on Jun 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Just add 'em up, if I understand you correctly. Some pseudocode ...
SELECT field1 + field2 + field3 AS total FROM table ORDER BY total;

ironik

1:26 am on Jun 28, 2005 (gmt 0)

10+ Year Member



Hehe, it had to be the easiest possible method. Thanks for the tip :D