473,671 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assign values based on Count(field_nam e) in query

I'm using Access 2000 on Windows 2000.

I have a DB of several exams and people who have taken them. I need
to assign ranks to the people according to their scores (within each
exam).

I have a select query written like this:
SELECT[list].[Score], Count([list].[Score]) AS Tally,[list].[Exam_Number]
FROM[list]
GROUP BY[list].[Score],[list].[Exam_Number]
HAVING ((([list].[Exam_Number])=[Enter Exam Number]))
ORDER BY[list].[Score] DESC;
So if the user were to enter "12345" as the Exam Number, the result
might look like this:
Score Tally Exam_Number
100 8 12345
95 2 12345
90 63 12345
85 2 12345
80 51 12345
70 29 12345

The ranking would be determined as follows:
All people with the highest score are ranked 1. In this example, 8
people are ranked 1 (100 would not necessarily be the highest score.)
The rank for the next lowest score is figured by adding the previous
rank number (1) to the number of people in that rank (8).
Thus, the 2 people with a score of 95 are ranked 9.
Then 9 + 2 = 11, so the 63 people with a score of 90 are ranked 11,
etc.

So a table of ranks for this exam would look like this:
Score Tally Rank
100 8 1
95 2 9
90 63 11
85 2 74
80 51 76
70 29 127

Ultimately a rank needs to be assigned to each person based on their
score.

What would be the best way to create this table of ranks and/or make
the rank assignment to each person?

Any assistance is appreciated.
Nov 13 '05 #1
2 2472
ra*****@hotmail .com (RBohannon) wrote in message news:<ad******* *************** ***@posting.goo gle.com>...
I'm using Access 2000 on Windows 2000.

I have a DB of several exams and people who have taken them. I need
to assign ranks to the people according to their scores (within each
exam).

I have a select query written like this:
SELECT[list].[Score], Count([list].[Score]) AS Tally,
[list].[Exam_Number]
FROM[list]
GROUP BY[list].[Score],[list].[Exam_Number]
HAVING ((([list].[Exam_Number])=[Enter Exam Number]))
ORDER BY[list].[Score] DESC;
So if the user were to enter "12345" as the Exam Number, the result
might look like this:
Score Tally Exam_Number
100 8 12345
95 2 12345
90 63 12345
85 2 12345
80 51 12345
70 29 12345

The ranking would be determined as follows:
All people with the highest score are ranked 1. In this example, 8
people are ranked 1 (100 would not necessarily be the highest score.)
The rank for the next lowest score is figured by adding the previous
rank number (1) to the number of people in that rank (8).
Thus, the 2 people with a score of 95 are ranked 9.
Then 9 + 2 = 11, so the 63 people with a score of 90 are ranked 11,
etc.

So a table of ranks for this exam would look like this:
Score Tally Rank
100 8 1
95 2 9
90 63 11
85 2 74
80 51 76
70 29 127

Ultimately a rank needs to be assigned to each person based on their
score.

What would be the best way to create this table of ranks and/or make
the rank assignment to each person?

Any assistance is appreciated.


By prepending a row to your results (can be done with a Union Query):

Score Tally ExamNumber
110 0 12345
100 8 12345
....

And running:
SELECT tblList.Score, tblList.Tally, tblList.ExamNum ber, (SELECT
SUM([Tally]) + 1 FROM tblList As GetRank WHERE tblList.Score <
GetRank.Score) AS Rank FROM tblList WHERE (Not (SELECT SUM([Tally]) +
1 FROM tblList As GetRank WHERE tblList.Score < GetRank.Score) Is
Null);

I got:
Score Tally ExamNumber Rank
100 8 12345 1
95 2 12345 9
90 63 12345 11
85 2 12345 74
80 51 12345 76
70 29 12345 127

I'm sure there's a technique buried in there somewhere for solving
this common problem. It can probably be done with a single SQL
statement.

James A. Fortune
Nov 13 '05 #2
ja******@oaklan d.edu (James Fortune) wrote in message news:<a6******* *************** ****@posting.go ogle.com>...
ra*****@hotmail .com (RBohannon) wrote in message news:<ad******* *************** ***@posting.goo gle.com>...
I'm using Access 2000 on Windows 2000.

I have a DB of several exams and people who have taken them. I need
to assign ranks to the people according to their scores (within each
exam).

I have a select query written like this:
SELECT[list].[Score], Count([list].[Score]) AS Tally,
[list].[Exam_Number]
FROM[list]
GROUP BY[list].[Score],[list].[Exam_Number]
HAVING ((([list].[Exam_Number])=[Enter Exam Number]))
ORDER BY[list].[Score] DESC;
So if the user were to enter "12345" as the Exam Number, the result
might look like this:
Score Tally Exam_Number
100 8 12345
95 2 12345
90 63 12345
85 2 12345
80 51 12345
70 29 12345

The ranking would be determined as follows:
All people with the highest score are ranked 1. In this example, 8
people are ranked 1 (100 would not necessarily be the highest score.)
The rank for the next lowest score is figured by adding the previous
rank number (1) to the number of people in that rank (8).
Thus, the 2 people with a score of 95 are ranked 9.
Then 9 + 2 = 11, so the 63 people with a score of 90 are ranked 11,
etc.

So a table of ranks for this exam would look like this:
Score Tally Rank
100 8 1
95 2 9
90 63 11
85 2 74
80 51 76
70 29 127

Ultimately a rank needs to be assigned to each person based on their
score.

What would be the best way to create this table of ranks and/or make
the rank assignment to each person?

Any assistance is appreciated.


By prepending a row to your results (can be done with a Union Query):

Score Tally ExamNumber
110 0 12345
100 8 12345
...

And running:
SELECT tblList.Score, tblList.Tally, tblList.ExamNum ber, (SELECT
SUM([Tally]) + 1 FROM tblList As GetRank WHERE tblList.Score <
GetRank.Score) AS Rank FROM tblList WHERE (Not (SELECT SUM([Tally]) +
1 FROM tblList As GetRank WHERE tblList.Score < GetRank.Score) Is
Null);

I got:
Score Tally ExamNumber Rank
100 8 12345 1
95 2 12345 9
90 63 12345 11
85 2 12345 74
80 51 12345 76
70 29 12345 127

I'm sure there's a technique buried in there somewhere for solving
this common problem. It can probably be done with a single SQL
statement.

James A. Fortune


Thanks for the help.

Writing code to do this in VB is a simple matter, but I'm not very
experienced with VBA and SQL. I tried using the results of the query
in VBA, but I'm having some difficulty with the proper references to
the database object, etc. For example, I wrote Dim dbs As Database
(like in the help file example) and I got an error message saying
"Database" was an undefined user-defined type.

So if I can do this in SQL, it may be easier for me now.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2351
by: Alex | last post by:
Subject: Looking for an XML (database-based) Query Reporting Tool/advice First off, let me apologize if this thread is somewhat off topic... PLEASE REPLY TO: xml@solex-bi.com I am looking for a way to query XML documents stored in an Oracle 9i database, contained in an unstructured CLOB column, much like one would with a traditional BI query reporting tool, but using XPath or XQuery
6
11493
by: Nicolae Fieraru | last post by:
Hi All, I have a query, Select Count(BoolField) from tblMyTable, Where BoolField = true. If I run the query by itself, it returns the number of true records I want to use the result of that query in my VBA code, like this: If (result of the query > 0) then do something
12
22784
by: briansmccabe | last post by:
Does anyone have a good approach to displaying in PHP a simple COUNT query that is performed on a table in a MySQL db? Thanks
6
5067
by: dBNovice | last post by:
Hey group, I am trying to do a count of the number of papers in a table. The table has a PaperID that differentiates each paper , e.g. 004.1. Some papers are reused. The reused paper is given a new PaperID. The PaperID includes 3 new numbers appended to the original PaperID, e.g. 664.004.1. When I do a count, I do not want to count the reused paper. I set up a count query and had the criteria { Not Like "***.***.*" }. I have also
2
2659
by: cwhite | last post by:
I'm having problems with a form based query The user makes a selection from a drop box, there are only two choices: Current Former the user makes a choice and clicks the preview report button and it runs the query into the form and nothing appears
2
2114
by: MLH | last post by:
Have a data entry form bound to a table. Has a save button on it that launches DoCmd.RunCommand acCmdSaveRecord in Access 97. In the form after-update code, I have a line looking something like this: LastVehicleJobID = DLookup("", "qryGetLastVehicleJobID") qryGetLastVehicleJobID looks something like this: SELECT TOP 1 tblVehicleJobs.VehicleJobID FROM tblVehicleJobs
1
1807
lwwhite
by: lwwhite | last post by:
When a user clicks OK on form "SelectDefaults," I want to open form "Welcome" if the results of query "qry_todo_overdue" = 0 or form "OverdueToDo" if the results >= 1. First, I assume that I need to run the query in "SelectDefault's" OnOpen event, right? But having done that, I'm not sure how to incorporate the query-checking into an If...Then statement on the OK button's OnClick event. Here is the query's SQL: SELECT Count(*) AS Expr1...
3
4869
WyvsEyeView
by: WyvsEyeView | last post by:
This seems like it should be so easy to do. I have a table, called tblTopics. Each topic can have one or more instances, contained in a table called tblTopicInst. tblTopics is bound to a form called frmTopics and tblTopicInst is bound to a form called frmTopicInst. From frmTopics, you access frmTopicInst via a button. I have also created a query, qryCountInst, that counts the number of instances for the topic currently displayed on frmTopics. I...
1
1611
by: MikeMikerson | last post by:
Hello, I am need to create a subform (no problem) of a form based query (a problem). I need a form that will prompt the user to enter in a name, and the form will then display a query of the persons transactions. The ideal situation would be that the executed query would remain as part of the record because there will be many of these "searches" stored within this form. I have:
0
8481
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8400
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8823
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8602
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.