Jan 6, 2011 #1 pushyr Programmer Joined Jul 2, 2007 Messages 159 Location 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
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
Jan 6, 2011 #2 r937 Technical User Joined Jun 30, 2002 Messages 8,847 Location CA Code: SELECT columnA , columnB , columnA/columnB AS ratio FROM daTable r937.com | rudy.ca Buy my new book Simply SQL from Amazon Upvote 0 Downvote
Code: SELECT columnA , columnB , columnA/columnB AS ratio FROM daTable r937.com | rudy.ca Buy my new book Simply SQL from Amazon
Jan 7, 2011 Thread starter #3 pushyr Programmer Joined Jul 2, 2007 Messages 159 Location GB 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 Upvote 0 Downvote
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
Jan 7, 2011 #4 ingresman IS-IT--Management Joined Feb 17, 2003 Messages 1,541 Location GB any help??? Code: select concat("1:",1/(columnA/cColumnB)) as ratio from daTable gives +----------+ | ratio | +----------+ | 1:5.0000 | +----------+ Click to expand... Upvote 0 Downvote
any help??? Code: select concat("1:",1/(columnA/cColumnB)) as ratio from daTable gives +----------+ | ratio | +----------+ | 1:5.0000 | +----------+ Click to expand...