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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.