Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Can't get a query to show me distinct # of items

Author  Topic 

ncp905
Starting Member

4 Posts

Posted - 2009-03-17 : 21:47:07
Hi I'm doing the following querry:

SELECT class.classCode,className, COUNT(csNum)AS 'Num Sections',COUNT(instructor.instrID)
AS 'Num Instructors', SUM(classHours) AS 'Total Class Hours' FROM class,instructor,class_section
WHERE class.classCode = class_section.classCode
AND instructor.instrID = class_section.instrID GROUP BY classCode
HAVING COUNT(DISTINCT instrLast);= (SELECT COUNT(*) FROM instructor);

i'm trying to get it to show the number of different teachers teaching a multiple section class and instead it's showing me the total teachers whether one teaches more than one section or not even though I have clause that's counting distinct teachers based on the subselect as our prof. pointed out in a the same example with fewer outputs and different tables, attributes,etc.

What would be the correct way to write this out?

Thanks

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2009-03-20 : 07:34:12
Can you include create table scripts / sample data
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-20 : 09:23:59
see this to find out way to post data

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -