Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using mysl queries to produce ratios

Status
Not open for further replies.

pushyr

Programmer
Jul 2, 2007
159
GB
is there a way to calculate ratios within a mysql query?

for example if i have 2 columns in the same table

column A = 10
column B = 2

then the ratio is 5:1

I normally do this using php but i'd now prefer to simplify things by doing as much as i can in the query
 
i was more thinking of creating maybe a string to express '5:1', as opposed to a decimal ratio '5'

here's an example of why i need to do this, if...

columnB = 10
columnA = 2,

then the ratio would be expressed as '1:5', as opposed to 0.2
 
any help???
Code:
 select concat("1:",1/(columnA/cColumnB)) as ratio from daTable

gives

+----------+
| ratio |
+----------+
| 1:5.0000 |
+----------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top