# creating a formula from row results and ranking

Page 1 of 1

## 2 Replies - 827 Views - Last Post: 25 January 2010 - 09:59 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=151862&amp;s=62e54f351cdacdb5625508da763771e8&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 1
• Posts: 70
• Joined: 08-June 09

# creating a formula from row results and ranking

Posted 25 January 2010 - 04:32 AM

Hi
Very new to SQL so apologies.
Say I have a table called results with 3 columns of data (record id, resultA and resultB)

table results
record, A , B
------------------
1 , 5 , 8
2 , 7 , 3
3 , 4 , 4
4 , 5 , 8
:
n , 8 , 1

I would like to create a formula that outputs a result query that ranks the records based on the formula A/B

Could someone give me a hand in figuring this out please
Many thanks

This post has been edited by javamad: 25 January 2010 - 04:33 AM

Is This A Good Question/Topic? 0

## Replies To: creating a formula from row results and ranking

• New D.I.C Head

Reputation: 3
• Posts: 20
• Joined: 13-July 09

## Re: creating a formula from row results and ranking

Posted 25 January 2010 - 06:01 AM

Hi,

Not sure if this is what you're looking for exactly, but from your question, I took it to mean you want to order the results of your table based on column A and B. If so, use order by A, B in your select statement. This will order the results (ascending by default) by column A, then by column B.

### #3 xerxes333

Reputation: 31
• Posts: 504
• Joined: 05-July 07

## Re: creating a formula from row results and ranking

Posted 25 January 2010 - 09:59 AM

@aadam21 I think he(she) wants the results of the calculation A/B sorted ascending. In which case you would want to execute the calculation A/B in the query and sort based on the calculation. A simple example would be
```SELECT A/B as calc FROM results ORDER BY calc ASC
```