Re: Calculating relative record numbers
- From: Marshall Barton <marshbarton@xxxxxxxxxx>
- Date: Mon, 26 Nov 2007 18:54:07 -0600
If you want them in ID order then that will work.
I don't see where you ultimately want to see this numbering,
but if it's in a report, then forget the query approach and
use a running sum text box with the expression =1
--
Marsh
MVP [MS Access]
Steve S wrote:
Couldn't I just use [Judge ID] as the 'sort field?' I do not care what the.
relationship is between the [Judge ID] and the relative number - just that
the relative number sequence starts with 1 and and is sequential (linear).
"Marshall Barton" wrote:
Steve S wrote:
The following SQL selects 8 records from a table [Judges].
SELECT Judges.[Judge ID], Judges.[Contest ID]
FROM Judges
WHERE (((Judges.[Contest ID])=30));
I want to add a column that will also display the relative record number as
shown below.
78 12 1
23 12 2
44 12 3
53 12 4
and so on.
Adding the additional column is not the problem: how to calculate or devise
the relative number is the problem
This is usually called a ranking query and it requires one
or more fields that can be used to produce a unique sorting
ot the records.
Here's an example that assumes you have a field named
SortField that meets that requirement:
SELECT Judges.[Judge ID], Judges.[Contest ID],
(SELECT Count(*)
FROM Judges As X
WHERE X.[Contest ID] = Judges.[Contest ID]
And X.SortField <= Judges.SortField) As Rank
FROM Judges
WHERE Judges.[Contest ID] = 30
If that's slow enough to notice, post back and we'll try
another way.
- Follow-Ups:
- Re: Calculating relative record numbers
- From: Steve S
- Re: Calculating relative record numbers
- From: Steve S
- Re: Calculating relative record numbers
- From: Steve S
- Re: Calculating relative record numbers
- References:
- Re: Calculating relative record numbers
- From: Marshall Barton
- Re: Calculating relative record numbers
- Prev by Date: Re: modifying field values in an Access 2003 query
- Next by Date: Re: Calculating relative record numbers
- Previous by thread: Re: Calculating relative record numbers
- Next by thread: Re: Calculating relative record numbers
- Index(es):
Relevant Pages
|
Loading