Re: Calculating relative record numbers
- From: Marshall Barton <marshbarton@xxxxxxxxxx>
- Date: Mon, 26 Nov 2007 16:50:09 -0600
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.
--
Marsh
MVP [MS Access]
.
- Prev by Date: Re: calculating maturity dates..
- Next by Date: RE: Calculating relative record numbers
- Previous by thread: How to sort columns in a Crosstab Query
- Next by thread: Re: Calculating relative record numbers
- Index(es):
Relevant Pages
|
Loading