Connecting Tech Pros Worldwide Forums | Help | Site Map

ORDER BY with floating point formula does not work?

Member
 
Join Date: Jun 2007
Posts: 38
#1: Jul 13 '07
Hello,
I have a problem getting 'Order By' to work properly on calculated results producing floating point value in MySql.

Ordering by single columns seems to work ok (like 'ORDER BY t2.Col4' in the query below).

This is a stripped version of my query:
Expand|Select|Wrap|Line Numbers
  1. SELECT t2.Col4, ROUND(SUM(t1.Col1 * t2.Col3) / SUM(t1.Col2), 2)
  2. FROM  Table1 AS t1, Table2 AS t2
  3. Where t1.Col4 = t2.Col1 ....
  4. GROUP BY t1.Col3
  5. ORDER BY ROUND(SUM(t1.Col1 * t2.Col3) / SUM(t1.Col2), 2);
  6.  
Any idea what it might be?
Could it be that I have the formula in the order by expression? If so, how can I specify which rendered column number I want to order by?
Note: do not pay attention to the where clause in this stripped version, in my unstripped version the where clause is complete and the rendered values are as expected.

best regards
Kurt

mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 719
#2: Jul 13 '07

re: ORDER BY with floating point formula does not work?


You can use alias for ORDER BY

Expand|Select|Wrap|Line Numbers
  1. SELECT t2.Col4, ROUND(SUM(t1.Col1 * t2.Col3) / SUM(t1.Col2), 2) AS total
  2. FROM Table1 AS t1, Table2 AS t2
  3. Where t1.Col4 = t2.Col1 ....
  4. GROUP BY t1.Col3
  5. ORDER BY total;
What you are expecting and what you are receving from the query? it will be better if you can describe by sample data.
Member
 
Join Date: Jun 2007
Posts: 38
#3: Jul 13 '07

re: ORDER BY with floating point formula does not work?


Thank you mwasif!
that was the fix
best regards
Kurt :-)
Reply


Similar MySQL Database bytes