dbTalk Databases Forums  

SQL quest

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss SQL quest in the comp.databases.xbase.fox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Greg Thomas
 
Posts: n/a

Default SQL quest - 08-20-2003 , 03:28 AM






Hi,

I am trying to write a query in MS Access. Say i have a table as
follows

Player, Date_Joined, Games_Player, Won, Lost, Points

As players win/lose they change position on the table.

I want to run a query the selects the Player and there Points AND i
want to add a colomnn to the query that ranks the players by score ie

Rank, Player, Points
1, Joe, 90
2, Rob, 78
3, Jim, 78
3, Bill, 70
4, Sam, 65

OR

Rank, Player, Points
1, Joe, 90
2, Rob, 78
3, Jim, 75
4, Bill, 70
5, Sam, 65

How do I add the Rank column (based on Points) if it does not exist in
any other tables?

Regards

Greg

Reply With Quote
  #2  
Old   
Cindy Winegarden
 
Posts: n/a

Default Re: SQL quest - 08-20-2003 , 10:55 PM






Hi Greg,

This newsgroup is for FoxPro and Visual FoxPro questions. While some of us
here work with Access I think you would you do better in an Access
newsgroup. There are lots on Microsoft's free news server,
msnews.microsoft.com.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
cindy.winegarden (AT) mvps (DOT) org, www.cindywinegarden.com

"Greg Thomas" <greg64thomas (AT) hotmail (DOT) com> wrote

Quote:
Hi,

I am trying to write a query in MS Access.



Reply With Quote
  #3  
Old   
Krister
 
Posts: n/a

Default Re: SQL quest - 08-21-2003 , 02:07 AM



Greg,
I assume that you query MS Access from Foxpro, since you post in this group.

Suggestion 1: Use the report variables in Foxpro's report writer and define
a variable which you increment for each row. Example:

Variable name: nRanking
Value to store: nRanking + 1
Initial value: 0

Then include the nRanking in the report and run it. If needed you can direct
the result to a text file for further processing.

Suggestion 2: Use a readwrite enabled cursor. Include numeric column with 0
in your query, then scan through the cursor and replace the value with the
ranking number, which you increment for each row.
select 000 as ranking, <field list> from <alias> into cursor temp order by
<ranking field>
*!* replace ranking with recno() all
*!* or
m.ranking = 0
scan
m.ranking = m.ranking + 1
replace ranking with m.ranking
endscan

Suggestion 3: Simply use the record number from the created cursor - it
holds the rank value, starting from 1.

Krister


"Greg Thomas" <greg64thomas (AT) hotmail (DOT) com> wrote

Quote:
Hi,

I am trying to write a query in MS Access. Say i have a table as
follows

Player, Date_Joined, Games_Player, Won, Lost, Points

As players win/lose they change position on the table.

I want to run a query the selects the Player and there Points AND i
want to add a colomnn to the query that ranks the players by score ie

Rank, Player, Points
1, Joe, 90
2, Rob, 78
3, Jim, 78
3, Bill, 70
4, Sam, 65

OR

Rank, Player, Points
1, Joe, 90
2, Rob, 78
3, Jim, 75
4, Bill, 70
5, Sam, 65

How do I add the Rank column (based on Points) if it does not exist in
any other tables?

Regards

Greg



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.