NeilAtTawanda


Hi

Please help! I'm really stuck. I have a table (AssessorAllocations) that stores the data of students who have submitted assessments for marking by an Assessor. Each time an assessment is submitted by a student my program must determine which Assessor has the smallest workload and then assign the current assessment to that Assessor. My problem is how do I determine which Assessor has the smallest number of assessments assigned to him/her.

The table columns are:

AssessorRegistrationNo

LearnerRegistrationNo

QualficationName

SubjectName

AssessmentName

DateAssigned

Marked

DateMarked

Price

So I'm looking for something like this:

Select AssessorRegistrationNo from AssessorAllocations where {Select the Assessor who has the smallest number of AssessmentNames assigned to him/her where Marked='0' and DateAssigned<>''}

Thanks

Neil




Re: Returning a value that has the smallest number of instances in a table

richbrownesq


Something like this may work:

Code Block

SELECT *

FROM (SELECT TOP 1 AssessorRegistrationNo, COUNT(*) AS NoAssignments

FROM MyTable

WHERE Marked = 0 AND DateAssigned IS NOT NULL

GROUP BY AssessorRegistrationNo

ORDER BY COUNT(*) DESC) AS Tbl

HTH!







Re: Returning a value that has the smallest number of instances in a table

Thomas Koelle

Above should not sort DESC but just normally.

Else you get the one with the highest workload.






Re: Returning a value that has the smallest number of instances in a table

NeilAtTawanda

Fantastic! Thank you so much to those who have helped me!

Neil

Johannesburg





Re: Returning a value that has the smallest number of instances in a table

richbrownesq

Thomas Koelle wrote:

Above should not sort DESC but just normally.

Else you get the one with the highest workload.

Oooops, my mistake- good spot Thomas!