SQL Help

Results 1 to 2 of 2

Thread: SQL Help

  1. #1
    Join Date
    Dec 1969

    Default SQL Help

    Hi,<BR><BR>I need to output a value to my page that isnt present in the database, but needs to be based on information from my database.<BR><BR>I was wondering if it is possible to display what number record you are in the database when sorted different ways...<BR><BR>Example:<BR><BR>I want to output to the page a list of RANKS in a league based on points so i want to be able to ORDER BY points DESC so that the highest points will be #1, #2 etc. but only out put what number I might be in that table ordered as above.<BR><BR>I hope you understand what im asking i basically want to display multiple records from the database and along with the information display their rank but their rank isnt in the database<BR><BR>1 way to do it woul dbe to loop right thru the records until it reaches the player i want to dosplay while incrementing a variable by 1 then stopping the loop when it reaches me ordered by POINTS DESC and outpu that value...<BR><BR>but this is not good programming i would think having to loop thru hundreds of records to display 1 value.<BR><BR>can you help?<BR><BR>Jay

  2. #2
    Join Date
    Dec 1969

    Default RE: SQL Help

    Select count(points) as rank from &#060;table&#062; where points &#060;<BR>(Select points from &#060;table&#062; where id = &#060;recordYouWant&#062;) order by points DESC<BR><BR>That should give you a ranking even if points are duplicated so if you have seventy records with 6 points and the record you want has 5 points he would be in the group that is seventy first <BR><BR>

Posting Permissions

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