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.
Author |
Topic |
sameergadade1
Starting Member
1 Post |
Posted - 2012-07-11 : 03:58:08
|
hi friends i am new to sql i have a table with fields Table=ATTENDANCEAttenid studentid teacherid repleceteacherid currentdat classid1 1 1 0 6/7/2012 12 2 0 2 7/7/2012 13 1 1 0 8/7/2012 1now i want to calculate teacher attendance between 2 dates each teacher is assigned to one class when teacher takes his class then his teacherid is get inserted to teacherid col(with replacement=0)and when other techer takes the class then his teacherid get inserted in replacementteacher col(with teacherid=0)i want the output in the following form totallectures presentlectures absentlectures 10 7 3how to write query if possible send me the queryplease help  |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-07-11 : 04:49:20
|
SELECT classid, SUM(Attenid) TotalLectures, SUM(CASE teacherid WHEN 1 THEN 1 ELSE 0 END) AS PresentLectures, SUM(CASE WHEN teacherid = 0 AND repleceteacherid > 0 THEN 1 ELSE 0 END) AS AbsentLecturesFROM ATTENDANCEWHERE currentdat >= '2012-06-07 00:00:00.000' AND currentdat <= '2012-08-07 00:00:00.000'GROUP BY classid--------------------------http://connectsql.blogspot.com/ |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-07-11 : 10:12:28
|
sorry but how do you determine a teachers absent lectures from current table design? As i understand it will just have replacementteacherid as teacher who replaced but it wont have any details of original lecture who was supposed to take class as its having 0 value------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|