ORDER BY with floating point formula does not work?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kurt Jakobsen
    New Member
    • Jun 2007
    • 38

    ORDER BY with floating point formula does not work?

    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:
    [code=sql]
    SELECT t2.Col4, ROUND(SUM(t1.Co l1 * t2.Col3) / SUM(t1.Col2), 2)
    FROM Table1 AS t1, Table2 AS t2
    Where t1.Col4 = t2.Col1 ....
    GROUP BY t1.Col3
    ORDER BY ROUND(SUM(t1.Co l1 * t2.Col3) / SUM(t1.Col2), 2);
    [/code]

    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
    Last edited by Atli; Jul 15 '07, 03:52 AM. Reason: Added code tags
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    You can use alias for ORDER BY

    [CODE=mysql]SELECT t2.Col4, ROUND(SUM(t1.Co l1 * t2.Col3) / SUM(t1.Col2), 2) AS total
    FROM Table1 AS t1, Table2 AS t2
    Where t1.Col4 = t2.Col1 ....
    GROUP BY t1.Col3
    ORDER BY total;[/CODE]

    What you are expecting and what you are receving from the query? it will be better if you can describe by sample data.

    Comment

    • Kurt Jakobsen
      New Member
      • Jun 2007
      • 38

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

      Comment

      Working...