Jump to content

mysql ORDER BY


birdie

Recommended Posts

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 points
draw = 1 point
loss = 0 points

would 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 time

any help appreciated, thanks
Link to comment
https://forums.phpfreaks.com/topic/6682-mysql-order-by/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/6682-mysql-order-by/#findComment-24306
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.