SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with ORDER BY Clause

    Hello MysQL Masters !

    I have a script that monitors the games played in a tournament and update the pool table accordingly.

    Now, have a look at this image:



    Our rule of sorting is this :

    1) Most Win
    2) Minimum Lost
    3) Minimum Runs Scored
    4) Maximum Runs Scored

    Now, if you can see the image again, first 2 records are GOOD as team ZEETESTING4 has won 2 games but allowed less runs as compared with ZEETESTING2.

    But the last 2 records are not good.
    you can see that ZEETESTING3 has allowed less runs as compared with ZEETESTING1.

    So here is what I want as result :

    Code:
    SEED   TEAM
    1        ZEETESTING4
    2        ZEETESTING2
    3        ZEETESTING3 
    4        ZEETESTING1
    Here is my current ORDER BY Clause.

    PHP Code:
    ORDER BY won DESC lostallowed ASC 
    Please help and guide me how I can achieve the desired results.

    Thanks
    Zeeshan
    Attached Images Attached Images

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You can translate your rule directly to query:
    Code:
    ORDER BY won DESC, lost ASC, scored ASC
    Though #4 makes no sense. You already sorted by runs scored in #3.

  3. #3
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot Sir ! its working

  4. #4
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh I made a mistake. I am sorry for that.

    The sorting rules are like this :

    1) Most Win
    2) Minimum Lost
    3) Minimum Runs Allowed
    4) Maximum Runs Scored

    For some reason, the previous suggestion is no more working, therefore I checked and found that I entered incorrect rules there.

    Can u still help me ?

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    ORDER BY win DESC, lost ASC, allowed ASC, scored DESC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    if ($zee == "Guru") { $zee--;}
    Join Date
    Nov 2005
    Location
    Karachi - Pakistan
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot Sir !


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •