birdie Posted April 5, 2006 Share Posted April 5, 2006 hi, ive used the order by function loads of times but have never used it this way.i have a mysql table like this..id|clanname|win|draw | loose |====================1|name1 |3 |2 | 1 | 2|name2 |4 |3 | 2 |how would i output the clannames ordered by the highest score first?win = 2 pointsdraw = 1 pointloss = 0 pointswould it be something like this.."SELECT clanname FROM table ORDER BY win*2,draw";i really have no clue and am now guessing at this timeany help appreciated, thanks Quote Link to comment https://forums.phpfreaks.com/topic/6682-mysql-order-by/ Share on other sites More sharing options...
akitchin Posted April 5, 2006 Share Posted April 5, 2006 i would create an intermediate value in your SELECT query, and refer to that in your WHERE clause:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] stuff, (wins*2 [color=orange]+[/color] draws [color=orange]-[/color] loose) [color=green]AS[/color] points [color=green]FROM[/color] [color=orange]table[/color] [color=green]WHERE[/color] stuff [color=green]ORDER BY[/color] points [color=green]DESC[/color] [!--sql2--][/div][!--sql3--]alternatively you can operate a much simpler ORDER BY, but i don't think it will give you what you want:[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] stuff [color=green]FROM[/color] [color=orange]table[/color] [color=green]WHERE[/color] stuff [color=green]ORDER BY[/color] wins DESC, loose ASC, draws [color=green]DESC[/color] [!--sql2--][/div][!--sql3--]that will select those with the most wins first. any ties in that set will then be grabbed in order of increasing losses. any ties in THAT will then be grabbed in order of most draws to fewest. Quote Link to comment https://forums.phpfreaks.com/topic/6682-mysql-order-by/#findComment-24306 Share on other sites More sharing options...
birdie Posted April 6, 2006 Author Share Posted April 6, 2006 ok thanks :-D Quote Link to comment https://forums.phpfreaks.com/topic/6682-mysql-order-by/#findComment-24610 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.