By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,822 Members | 729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,822 IT Pros & Developers. It's quick & easy.

ORDER BY with floating point formula does not work?

P: 38
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
Jul 13 '07 #1
Share this Question
Share on Google+
2 Replies


mwasif
Expert 100+
P: 801
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.
Jul 13 '07 #2

P: 38
Thank you mwasif!
that was the fix
best regards
Kurt :-)
Jul 13 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.