February 15, 2010 at 3:17 pm
Class table has people with the role of students and teachers. There should be at least one teacher in a class or every one is a student.
How do I write a query so that for a given class type there should be at least one teacher available or every one is a student. i. if not teacher is available or every person in the class is a student then the query should return a zero, else one
Table structure is
CLASS
id
class_type_id
person_type
Name
e.g
id class_type_id person_type Name
1 First Teacher John
2 First Student Bobby
3 First Student Kathy
4 First Student Tony
6 First Teacher Kate
7 First Teacher John
8 First Student Betty
9 First Student Snowy
Thanks in advance as always
AK
February 15, 2010 at 4:40 pm
Sounds like a homework question....
If yes: what specific question do you have? We usually don't do someone's homework, but we'll be happy to assist you if you got stuck (which would expect that you started working on it on your own...) or if you have a specific question about how some SQL code works.
If it's not homework: please describe the business case and include sample data as per the first link in my signature including expected result set and what you've tried so far.
February 15, 2010 at 5:24 pm
That's a good one. No this is not a H/W Question.
We have a case where we need to get all the records which has a specific criteria. I had generalized my question into the Teacher student example.
I can get this to work by selecting all the values and filtering them in the front end. Trying to figure out if this can be avoided by using one SQL query
A-
February 16, 2010 at 11:47 am
Ash-N (2/15/2010)
That's a good one. No this is not a H/W Question.We have a case where we need to get all the records which has a specific criteria. I had generalized my question into the Teacher student example.
I can get this to work by selecting all the values and filtering them in the front end. Trying to figure out if this can be avoided by using one SQL query
A-
So you shold follow the 2nd path described in my prev. post then...
To answer your question (if its possible to do using TSQL) as brief as the description is: it depends. With a strong trend towards yes.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply