Solved Grouped ranking (1 Viewer)

gregoryhills

New member
Local time
Today, 21:58
Joined
Feb 14, 2022
Messages
15
Hi. Check REPORT FORMS in REPORTS in this database. I need a query or function to rank Students per class and per the stream at a certain year and a term e.g
Year- 2022
Term- Term 1
Student Name- X
Class position..... Out of ...........(Students in a class)
Stream Position....... Out of(Students in a class)
Lastly how can I refer to last exams total marks per student.
I have highlighted in yellow in the report.
Any help will be highly appreciated.
 

Attachments

  • GROUPEDRANKING.zip
    147.4 KB · Views: 293

gregoryhills

New member
Local time
Today, 21:58
Joined
Feb 14, 2022
Messages
15
Someone kindly assist me
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:58
Joined
Jan 20, 2009
Messages
12,852
One way is to do a DCount of students with higher grades where they have the same criteria as the record being ranked then add one.
This function must run for each record so it is very slow.

The number of students can be done with a Count(), GROUP BY the criteria. Then join this to the other query.

Access isn't very good at ranking.

TSQL used in SQL Server has functions ROW_NUMBER and RANK combined with PARTITION BY and ORDER BY that do the job very simply and efficiently.
 

gregoryhills

New member
Local time
Today, 21:58
Joined
Feb 14, 2022
Messages
15
One way is to do a DCount of students with higher grades where they have the same criteria as the record being ranked then add one.
This function must run for each record so it is very slow.

The number of students can be done with a Count(), GROUP BY the criteria. Then join this to the other query.

Access isn't very good at ranking.

TSQL used in SQL Server has functions ROW_NUMBER and RANK combined with PARTITION BY and ORDER BY that do the job very simply and efficiently.
You are complicating even further. I have been working on it for the last two weeks without success. Kindly look at the attached database and assist me. It has given me headaches.😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭😭
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:58
Joined
May 21, 2018
Messages
8,529
You are complicating even further.
FYI,
If you come asking for help and some expert provides a good working answer, you should not criticize and keep on whining. It does not endear people to help you. Try a little sugar.
The dcount idea is a tried and true method in Access for doing a group by query. If not you have to use a subquery. Both methods are here.

You data is really poor for demonstration. All are in the same stream. It would be helpful to have some data. Grouping by a single stream is not very illustrative.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 14:58
Joined
May 21, 2018
Messages
8,529
Maybe something like this but the grouping is not clear to me
Code:
SELECT A.stream,
       A.description,
       A.[student name],
       A.years,
       A.gradedesc,
       A.term,
       A.sumofmark,
       (SELECT Count(*) + 1
        FROM   qryallmarks AS b
        WHERE  A.stream = b.stream
               AND A.years = B.years
               AND A.gradedesc = B.gradedesc
               AND B.sumofmark
               AND A.description = b.description
               AND B.sumofmark < A.sumofmark) AS ClassRank
FROM   qryallmarks AS A
ORDER  BY A.description,
          A.years,
          A.gradedesc;
Query1 Query1

Query1 Query1

STREAMYearsDescriptionStudent NameGradeDescTERMSumOfMarkClassRank
WEST
2020​
AgricultureCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2020​
AviationCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2020​
Business StudiesCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2022​
AgricultureSHARON AWINOFORM 1Term 1
10​
1​
WEST
2022​
AgricultureMERCY CHEBETFORM 1Term 1
50​
2​
WEST
2022​
AgricultureSHEILA CHEBET ISAACFORM 1Term 1
50​
2​
WEST
2022​
AgricultureCLINTON KIPROTICHFORM 1Term 1
50​
2​
WEST
2022​
AgricultureGILBERT KIPKOECHFORM 1Term 1
50​
2​
WEST
2022​
AgricultureGLAVIN KIPKOECH ROPFORM 1Term 1
50​
2​
WEST
2022​
AgricultureMILLICENT CHEPKOECHFORM 1Term 1
50​
2​
WEST
2022​
ArabicMERCY CHEBETFORM 1Term 1
30​
1​
WEST
2022​
ArabicSHARON AWINOFORM 1Term 1
30​
1​
WEST
2022​
ArabicSHEILA CHEBET ISAACFORM 1Term 1
50​
3​
WEST
2022​
ArabicMILLICENT CHEPKOECHFORM 1Term 1
50​
3​
WEST
2022​
ArabicGLAVIN KIPKOECH ROPFORM 1Term 1
50​
3​
WEST
2022​
Art And DesignCLINTON KIPROTICHFORM 1Term 1
50​
1​
WEST
2022​
Art And DesignMERCY CHEBETFORM 1Term 1
80​
2​
WEST
2022​
AviationCLINTON KIPROTICHFORM 1Term 1
50​
1​
WEST
2022​
BiologySHARON AWINOFORM 1Term 1
30​
1​
WEST
2022​
BiologyMILLICENT CHEPKOECHFORM 1Term 1
50​
2​
WEST
2022​
BiologyCLINTON KIPROTICHFORM 1Term 1
50​
2​
WEST
2022​
ElectricityMILLICENT CHEPKOECHFORM 1Term 1
50​
1​
WEST
2022​
FrenchMILLICENT CHEPKOECHFORM 1Term 1
50​
1​
 

gregoryhills

New member
Local time
Today, 21:58
Joined
Feb 14, 2022
Messages
15
Let me replace the query qryAllMarks with QueryTotalMarks. I appreciate your efforts. Thanks
 

gregoryhills

New member
Local time
Today, 21:58
Joined
Feb 14, 2022
Messages
15
Maybe something like this but the grouping is not clear to me
Code:
SELECT A.stream,
       A.description,
       A.[student name],
       A.years,
       A.gradedesc,
       A.term,
       A.sumofmark,
       (SELECT Count(*) + 1
        FROM   qryallmarks AS b
        WHERE  A.stream = b.stream
               AND A.years = B.years
               AND A.gradedesc = B.gradedesc
               AND B.sumofmark
               AND A.description = b.description
               AND B.sumofmark < A.sumofmark) AS ClassRank
FROM   qryallmarks AS A
ORDER  BY A.description,
          A.years,
          A.gradedesc;
Query1 Query1

Query1 Query1

STREAMYearsDescriptionStudent NameGradeDescTERMSumOfMarkClassRank
WEST
2020​
AgricultureCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2020​
AviationCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2020​
Business StudiesCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2022​
AgricultureSHARON AWINOFORM 1Term 1
10​
1​
WEST
2022​
AgricultureMERCY CHEBETFORM 1Term 1
50​
2​
WEST
2022​
AgricultureSHEILA CHEBET ISAACFORM 1Term 1
50​
2​
WEST
2022​
AgricultureCLINTON KIPROTICHFORM 1Term 1
50​
2​
WEST
2022​
AgricultureGILBERT KIPKOECHFORM 1Term 1
50​
2​
WEST
2022​
AgricultureGLAVIN KIPKOECH ROPFORM 1Term 1
50​
2​
WEST
2022​
AgricultureMILLICENT CHEPKOECHFORM 1Term 1
50​
2​
WEST
2022​
ArabicMERCY CHEBETFORM 1Term 1
30​
1​
WEST
2022​
ArabicSHARON AWINOFORM 1Term 1
30​
1​
WEST
2022​
ArabicSHEILA CHEBET ISAACFORM 1Term 1
50​
3​
WEST
2022​
ArabicMILLICENT CHEPKOECHFORM 1Term 1
50​
3​
WEST
2022​
ArabicGLAVIN KIPKOECH ROPFORM 1Term 1
50​
3​
WEST
2022​
Art And DesignCLINTON KIPROTICHFORM 1Term 1
50​
1​
WEST
2022​
Art And DesignMERCY CHEBETFORM 1Term 1
80​
2​
WEST
2022​
AviationCLINTON KIPROTICHFORM 1Term 1
50​
1​
WEST
2022​
BiologySHARON AWINOFORM 1Term 1
30​
1​
WEST
2022​
BiologyMILLICENT CHEPKOECHFORM 1Term 1
50​
2​
WEST
2022​
BiologyCLINTON KIPROTICHFORM 1Term 1
50​
2​
WEST
2022​
ElectricityMILLICENT CHEPKOECHFORM 1Term 1
50​
1​
WEST
2022​
FrenchMILLICENT CHEPKOECHFORM 1Term 1
50​
1​
It works. However I am defeated to insert the number of students who did exams. Should be
CLASSRANK: 1 OUT OF (NUMBER OF STUDENTS WHO DID EXAMS.)
E.G MILLICENT CHEPKOECH
CLASSRANK: 1 OUT OF 7 FORM 1 WEST 2022
 

gregoryhills

New member
Local time
Today, 21:58
Joined
Feb 14, 2022
Messages
15
Th
Maybe something like this but the grouping is not clear to me
Code:
SELECT A.stream,
       A.description,
       A.[student name],
       A.years,
       A.gradedesc,
       A.term,
       A.sumofmark,
       (SELECT Count(*) + 1
        FROM   qryallmarks AS b
        WHERE  A.stream = b.stream
               AND A.years = B.years
               AND A.gradedesc = B.gradedesc
               AND B.sumofmark
               AND A.description = b.description
               AND B.sumofmark < A.sumofmark) AS ClassRank
FROM   qryallmarks AS A
ORDER  BY A.description,
          A.years,
          A.gradedesc;
Query1 Query1

Query1 Query1

STREAMYearsDescriptionStudent NameGradeDescTERMSumOfMarkClassRank
WEST
2020​
AgricultureCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2020​
AviationCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2020​
Business StudiesCHARITY CHEPTOOFORM 4Term 1
100​
1​
WEST
2022​
AgricultureSHARON AWINOFORM 1Term 1
10​
1​
WEST
2022​
AgricultureMERCY CHEBETFORM 1Term 1
50​
2​
WEST
2022​
AgricultureSHEILA CHEBET ISAACFORM 1Term 1
50​
2​
WEST
2022​
AgricultureCLINTON KIPROTICHFORM 1Term 1
50​
2​
WEST
2022​
AgricultureGILBERT KIPKOECHFORM 1Term 1
50​
2​
WEST
2022​
AgricultureGLAVIN KIPKOECH ROPFORM 1Term 1
50​
2​
WEST
2022​
AgricultureMILLICENT CHEPKOECHFORM 1Term 1
50​
2​
WEST
2022​
ArabicMERCY CHEBETFORM 1Term 1
30​
1​
WEST
2022​
ArabicSHARON AWINOFORM 1Term 1
30​
1​
WEST
2022​
ArabicSHEILA CHEBET ISAACFORM 1Term 1
50​
3​
WEST
2022​
ArabicMILLICENT CHEPKOECHFORM 1Term 1
50​
3​
WEST
2022​
ArabicGLAVIN KIPKOECH ROPFORM 1Term 1
50​
3​
WEST
2022​
Art And DesignCLINTON KIPROTICHFORM 1Term 1
50​
1​
WEST
2022​
Art And DesignMERCY CHEBETFORM 1Term 1
80​
2​
WEST
2022​
AviationCLINTON KIPROTICHFORM 1Term 1
50​
1​
WEST
2022​
BiologySHARON AWINOFORM 1Term 1
30​
1​
WEST
2022​
BiologyMILLICENT CHEPKOECHFORM 1Term 1
50​
2​
WEST
2022​
BiologyCLINTON KIPROTICHFORM 1Term 1
50​
2​
WEST
2022​
ElectricityMILLICENT CHEPKOECHFORM 1Term 1
50​
1​
WEST
2022​
FrenchMILLICENT CHEPKOECHFORM 1Term 1
50​
1​
Thanks to you I have found the solution. Thanks so much.
 

Gasman

Enthusiastic Amateur
Local time
Today, 19:58
Joined
Sep 21, 2011
Messages
14,310
So please share the solution. This is what this site is all about after all?
 

SHANEMAC51

Active member
Local time
Today, 21:58
Joined
Jan 28, 2022
Messages
310
Lastly how can I refer to last exams total marks per student.
I didn't really understand how LASTEXAMS TOTAL MARKS
differs from TOTAL MARKS
 

Attachments

  • wa25.pdf
    525.7 KB · Views: 274
  • Screenshot_2.png
    Screenshot_2.png
    26.2 KB · Views: 234

SHANEMAC51

Active member
Local time
Today, 21:58
Joined
Jan 28, 2022
Messages
310
I didn't really understand how LASTEXAMS TOTAL MARKS
differs from TOTAL MARKS
main query
streamStudent IDstudent nameyearsgradedesctermSum of markAvg- MarkClass RankStream RankClass Rank2 avgStream Rank2 avg
WEST83MERCY CHEBET2022FORM 1Term 1260652211
WEST9SHEILA CHEBET ISAAC2022FORM 1Term 1180603422
WEST23GILBERT KIPKOECH2022FORM 1Term 1120605622
WEST52CLINTON KIPROTICH2022FORM 1Term 1280561144
WEST2MILLICENT CHEPKOECH2022FORM 4Term 1250501315
WEST15GLAVIN KIPKOECH ROP2022FORM 1Term 1100506755
WEST65SHARON AWINO2022FORM 1Term 1160404567
 

Users who are viewing this thread

Top Bottom