Percentage (1 Viewer)

cktcPeterson

Member
Local time
Today, 11:32
Joined
Mar 23, 2022
Messages
73
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?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:32
Joined
Feb 19, 2013
Messages
16,616
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:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 14:32
Joined
Feb 28, 2001
Messages
27,188
Not to mention that there is another aggregate called AVG that would fit in with the "SELECT" clause.

 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:32
Joined
Feb 19, 2002
Messages
43,280
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

Top Bottom