nickn Posted November 17, 2003 Share Posted November 17, 2003 Here is the basic fields of a table. field 1, field 2, field 3. Field 1 is varchar, 2 and 2 are int. Select field1, sum(field2), sum(field3) GROUP BY field1 ORDER BY ??? sum(field2)??? I am trying to put the returned results in order from the sum of field 2 ie... field1 field 2 field3 nick 20 2 matt 10 4 jason 5 1 Another Question. Can I order by 2 sums that have been divided. ie... SELECT field1, sum(field2), sum(field3) FROM TABLE GROUP BY field1 ORDER BY (field2 / field3) DESC Again with the sum of 2 fields, then divided to get an avg between the 2 sums and ordered correctly by the avg. ie... field 1 field2 field3 AVG nick 20 5 4 matt 15 5 3 jason 10 5 2 Quote Link to comment https://forums.phpfreaks.com/topic/1380-couple-questions-query-related/ Share on other sites More sharing options...
sirmanson Posted November 18, 2003 Share Posted November 18, 2003 You can order by any formula you wish Either of these will work : select col1, col2/col3 from table order by col1/col2 or select col1, col2/col3 from table order by col2/col3 Quote Link to comment https://forums.phpfreaks.com/topic/1380-couple-questions-query-related/#findComment-4593 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.