Jump to content

COUNT Query Help


db1993

Recommended Posts

Hello, I am having difficulties with this class work question

 

List the various courseTitles, and for each course with the number of 

female students registered. Order the list by descending counts.

 

 

The query I have used so far:

 


SELECT course.courseTitle, COUNT(DISTINCT student.sex)

FROM course, student

WHERE student.sex = 'f'


 

 

There are 2 Course Titles but the output of the above query only displays the first Course Title instead of both.

Also, instead of displaying the count of 'F' (females) as 6 it displays it as 1

Link to comment
https://forums.phpfreaks.com/topic/283474-count-query-help/
Share on other sites

COUNT(DISTINCT sex)  counts how many different sexes there are where the sex = F ie 1.

 

You join "courses, students" is wrong. This will give a cartesian join, joining every course record with every student record. If you have 10 courses and 100 students you will get 1000 rows returned.

 

You must specify how the tables are related eg

FROM course JOIN student ON course.somefield = student.otherfield
Link to comment
https://forums.phpfreaks.com/topic/283474-count-query-help/#findComment-1456382
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.