|
pejeguerrero
Starting Member
2 Posts |
Posted - 2010-01-07 : 13:56:12
|
| Hello everyone, I'm having trouble writing a query to return a count of students by gender and how many are taking specific courses (Lessons/Classes).These are the tables that I'm using to pull the information from ...Table Courses-------------------------------CourseID,StudentID,CourseTypeID1001,1001,11002,1002,11003,1002,21004,1003,11005,1001,2Table Students-------------------------------StudentID,Name,GenderID1001,John Smith,11002,Maria Perez,01003,Marcus Dell,1Table Course Types-------------------------------CourseTypeID,Name1,Course #12,Course #23,Course #34,Course #4Can someone show me the light on how to return the following result?Course Name,Male,Female,TotalCourse #1,2,1,3Course #2,1,1,2Thanks in advance ... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-07 : 14:00:14
|
| [code]SELECT ct.Name,SUM(CASE WHEN s.GenderID=1 THEN 1 ELSE 0 END) AS Male,SUM(CASE WHEN s.GenderID=0 THEN 1 ELSE 0 END) AS Female,COUNT(StudentID) AS TotalFROM CourseType ctINNER JOIN Courses cON c.CourseTypeID=ct.CourseTypeIDINNER JOIN Students sON s.StudentID=c.StudentIDGROUP BY ct.Name[/code] |
 |
|