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 |
razeena
Yak Posting Veteran
54 Posts |
Posted - 2013-04-18 : 05:00:13
|
Hi, I have three tables related to Question Papers. The objective is to find out how many users attended these papers. Each question paper may contain different sections. Even if a person attended atleast onesection, the paper is considered as attended. Please see the sampletable and expected output. =================================tbl_Question***********QID title description100 History History101 Maths Maths102 Hindi Hinditbl_QuestionSection**********************SectionID QID SectionName1 100 IndianHistory2 100 WorldHistory3 100 StateHistory4 101 Statistics5 101 Probability6 102 General7 102 Descriptivetbl_UserSection*****************UserSecID UserID QpSecID1 500 22 500 33 501 14 502 15 503 5==================================Expected result-----------------------------QuestionPaper NoofAttendeesHistory 3 Maths 1 Hindi 0------------------------------- |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-18 : 05:14:38
|
[code]SELECT q.title,COUNT(DISTINCT UserID) AS NoOfAttendeesFROM tbl_Question qLEFT JOIN tbl_QuestionSection qsON qs.QID = q.QIDLEFT JOIN tbl_UserSection usON us.QpSecID = qs.SectionIDGROUP BY q.title[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
razeena
Yak Posting Veteran
54 Posts |
Posted - 2013-04-22 : 01:56:23
|
Perfect! It worked.Thank you.quote: Originally posted by visakh16
SELECT q.title,COUNT(DISTINCT UserID) AS NoOfAttendeesFROM tbl_Question qLEFT JOIN tbl_QuestionSection qsON qs.QID = q.QIDLEFT JOIN tbl_UserSection usON us.QpSecID = qs.SectionIDGROUP BY q.title ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-04-22 : 04:28:12
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|