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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.