Count single record if duplicate exists (1 Viewer)

sherikream

Registered User.
Local time
Today, 17:41
Joined
Mar 27, 2013
Messages
14
I want to do a count of total courses a student has passed, not including a duplicated course.

Students are required to pass 5 courses. But may have taken a course more than once to earn a higher grade even if already passed. Is there any "Count" expression or another expression to count total passed course, but not include the duplicate, for each student. Preferably keep the lower grade, for GPA calculation.

Example data below:
(if I do plain >=5 count for the below data, it counts both duplicates, which I don't want)

Course1-A
Course2-C (duplicate course, although different grade)
Course2-D (duplicate course, although different grade)
Course3-B
Course4-A
Course5-C

I need it to count only the following:
Course1-A
Course2-D (duplicate course, although different grade)
Course3-B
Course4-A
Course5-C

Thank you all in advance for any assistance.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:41
Joined
May 7, 2009
Messages
19,229
Select Count(*) From (Select Course From table1 Group By Course);

Or

Select Count(*) From (Select Distinct Course From table1);
 

plog

Banishment Pending
Local time
Today, 16:41
Joined
May 11, 2011
Messages
11,638
You are asking for 2 different things--a count of unique courses passed and the lowest grade of each course passed. The example you provided showed how you wanted the lowest grade for each course passed, below is the SQL for that:

Code:
SELECT CourseName, MIN(CourseGrade) AS LowestGrade
FROM YourTableNameHere
GROUP BY CourseName;

arnelgp gave you the other.
 

sherikream

Registered User.
Local time
Today, 17:41
Joined
Mar 27, 2013
Messages
14
Select Count(*) From (Select Course From table1 Group By Course);

Or

Select Count(*) From (Select Distinct Course From table1);


Where in my SQL should I add your coding?

Code:
SELECT Courses.ID, Count(Courses.CourseID) AS Passed
FROM Courses
WHERE (((Courses.Grade) Is Not Null) AND ((Courses.GradePoint)>0)) OR (((Courses.GradePoint)=-1))
GROUP BY Courses.ID
HAVING (((Count(Courses.CourseID))>=10 Or (Count(Courses.CourseID))>=10))
ORDER BY Courses.ID;
 

Cronk

Registered User.
Local time
Tomorrow, 07:41
Joined
Jul 4, 2013
Messages
2,771
Arnel, Plog

I want to do a count of total courses a student has passed

You'll need to include Students in your query grouping
 

Users who are viewing this thread

Top Bottom