Percentage

cktcPeterson

Member
Local time
Today, 01:48
Joined
Mar 23, 2022
Messages
74
I have a query with list of students and and field that they pick yes or no.

I want to create a query/report to where I have a list of student and the course they sigend up for, and ther number of yes over the total of participants.


Example
Course
55 (yes)/150 (no)

How would I go about setting this up?
 
Depends on your table design and relationships but a broad answer would be to use an aggregate query, group on course , sum the yeses and count the records

select course, sum(abs(yeses)) as numberyes, count(*) as numbercount
From mytable
Group by course

then another query based on this to divide one by the other
 
Last edited:
Not to mention that there is another aggregate called AVG that would fit in with the "SELECT" clause.

 
I have a query with list of students and and field that they pick yes or no.
This is not the way the tables should be defined.

You need a minimum of three tables. Students, Courses, StudentCourses.
The Students table contains a row for each Student. The Courses table contains a row for each course. StudentCourses contains a row for each student in a particular course. This is a typical many-many relationship. The count would be obtained from StudentCourses. You would join to the Courses table to get a description of the Course name. The query might look like

Select tblCourses.CourseName, Count(*) as StudentsEnrolled
From tblCourses Inner Join tblStudentCourses on tblCourses.CourseID = tblStudentCourses.CourseID
Group by tblCourses.CourseName;

This sample database shows how a m-m works.

 

Users who are viewing this thread

Back
Top Bottom