StudentCountView.sql 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. select
  2. schoolyear.Code as SchoolyearCode,
  3. classCount.*,
  4. StudentMaleCount.StudentMaleCount,
  5. StudentFemaleCount.StudentFemaleCount
  6. from (
  7. select
  8. campus.CampusID,
  9. campus.No as CampusNo,
  10. campus.Name as CampusName,
  11. college.CollegeID,
  12. college.No as CollegeNo,
  13. college.Name as CollegeName,
  14. faculty.StandardID,
  15. [standard].Name as StandardName,
  16. grade.GradeID as GradeYear,
  17. faculty.EducationID,
  18. education.Name as EducationName,
  19. student.StudentType,
  20. studentType.Name as StudentTypeName,
  21. COUNT(distinct class.ClassmajorID) as ClassmajorCount
  22. from [dbo].CF_Campus campus
  23. inner join [dbo].[CF_College] college on college.CampusID =campus.CampusID
  24. inner join [dbo].[CF_Facultymajor] faculty on college.CollegeID=faculty.CollegeID
  25. inner join [dbo].[CF_Grademajor] grade on faculty.FacultymajorID=grade.FacultymajorID
  26. inner join [dbo].[CF_Classmajor] class on grade.GrademajorID=class.GrademajorID
  27. inner join [dbo].[CF_Student] student on class.ClassmajorID=student.ClassmajorID
  28. inner join [dbo].[Sys_DictionaryItem] [standard] on faculty.StandardID=[standard].Value and [standard].DictionaryCode='CF_Standard'
  29. inner join [dbo].[Sys_DictionaryItem] education on faculty.EducationID=education.Value and education.DictionaryCode='CF_Education'
  30. inner join [dbo].[Sys_DictionaryItem] studentType on student.StudentType=studentType.Value and studentType.DictionaryCode='CF_STUDENTTYPE'
  31. left join [dbo].[CF_InSchoolSetting] inschoolset on student.InSchoolStatusID=inschoolset.InSchoolStatusID
  32. where
  33. ((@InSchoolStatusID is null or @InSchoolStatusID=0)
  34. or (case when @InSchoolStatusID=1 then 1 else 0 end=ISNULL(inschoolset.IsSelected,0)))
  35. group by campus.CampusID,campus.No,campus.Name,college.CollegeID,college.No,college.Name,faculty.StandardID,[standard].Name,grade.GradeID,faculty.EducationID,education.Name,student.StudentType,studentType.Name) classCount
  36. left join
  37. (select
  38. campus.CampusID,
  39. campus.Name as CampusName,
  40. college.CollegeID,
  41. college.Name as CollegeName,
  42. faculty.StandardID,
  43. [standard].Name as StandardName,
  44. grade.GradeID as GradeYear,
  45. faculty.EducationID,
  46. education.Name as EducationName,
  47. student.StudentType,
  48. studentType.Name as StudentTypeName,
  49. student.SexID AS Sex,
  50. sex.Name as SexName,
  51. COUNT(distinct student.UserID) as StudentMaleCount
  52. from [dbo].CF_Campus campus
  53. inner join [dbo].[CF_College] college on college.CampusID =campus.CampusID
  54. inner join [dbo].[CF_Facultymajor] faculty on college.CollegeID=faculty.CollegeID
  55. inner join [dbo].[CF_Grademajor] grade on faculty.FacultymajorID=grade.FacultymajorID
  56. inner join [dbo].[CF_Classmajor] class on grade.GrademajorID=class.GrademajorID
  57. inner join [dbo].[CF_Student] student on class.ClassmajorID=student.ClassmajorID
  58. inner join [dbo].[Sys_DictionaryItem] [standard] on faculty.StandardID=[standard].Value and [standard].DictionaryCode='CF_Standard'
  59. inner join [dbo].[Sys_DictionaryItem] education on faculty.EducationID=education.Value and education.DictionaryCode='CF_Education'
  60. inner join [dbo].[Sys_DictionaryItem] sex on student.SexID=sex.Value and sex.DictionaryCode='CF_Sex'
  61. inner join [dbo].[Sys_DictionaryItem] studentType on student.StudentType=studentType.Value and studentType.DictionaryCode='CF_STUDENTTYPE'
  62. left join [dbo].[CF_InSchoolSetting] inschoolset on student.InSchoolStatusID=inschoolset.InSchoolStatusID
  63. where ((@InSchoolStatusID is null or @InSchoolStatusID=0)
  64. or (case when @InSchoolStatusID=1 then 1 else 0 end=ISNULL(inschoolset.IsSelected,0)))
  65. group by campus.CampusID,campus.Name,college.CollegeID,college.Name,faculty.StandardID,[standard].Name,grade.GradeID,
  66. faculty.EducationID,education.Name,student.StudentType,studentType.Name,student.SexID,sex.Name,sex.Code having sex.Code='Male'
  67. ) studentMaleCount
  68. on classCount.CampusID=studentMaleCount.CampusID
  69. and classCount.CollegeID=studentMaleCount.CollegeID
  70. and classCount.StandardID=studentMaleCount.StandardID
  71. and classCount.GradeYear=studentMaleCount.GradeYear
  72. and classCount.EducationID=studentMaleCount.EducationID
  73. and classCount.StudentType=studentMaleCount.StudentType
  74. left join
  75. (select campus.CampusID,campus.Name as CampusName,college.CollegeID,college.Name as CollegeName,
  76. faculty.StandardID,[standard].Name as StandardName,grade.GradeID as GradeYear,
  77. faculty.EducationID,education.Name as EducationName,student.StudentType,studentType.Name as StudentTypeName,
  78. student.SexID AS Sex,sex.Name as SexName,
  79. COUNT(distinct student.UserID) as StudentFemaleCount
  80. from [dbo].CF_Campus campus
  81. inner join [dbo].[CF_College] college on college.CampusID =campus.CampusID
  82. inner join [dbo].[CF_Facultymajor] faculty on college.CollegeID=faculty.CollegeID
  83. inner join [dbo].[CF_Grademajor] grade on faculty.FacultymajorID=grade.FacultymajorID
  84. inner join [dbo].[CF_Classmajor] class on grade.GrademajorID=class.GrademajorID
  85. inner join [dbo].[CF_Student] student on class.ClassmajorID=student.ClassmajorID
  86. inner join [dbo].[Sys_DictionaryItem] [standard] on faculty.StandardID=[standard].Value and [standard].DictionaryCode='CF_Standard'
  87. inner join [dbo].[Sys_DictionaryItem] education on faculty.EducationID=education.Value and education.DictionaryCode='CF_Education'
  88. inner join [dbo].[Sys_DictionaryItem] sex on student.SexID=sex.Value and sex.DictionaryCode='CF_Sex'
  89. inner join [dbo].[Sys_DictionaryItem] studentType on student.StudentType=studentType.Value and studentType.DictionaryCode='CF_STUDENTTYPE'
  90. left join [dbo].[CF_InSchoolSetting] inschoolset on student.InSchoolStatusID=inschoolset.InSchoolStatusID
  91. where ((@InSchoolStatusID is null or @InSchoolStatusID=0)
  92. or (case when @InSchoolStatusID=1 then 1 else 0 end=ISNULL(inschoolset.IsSelected,0)))
  93. group by campus.CampusID,campus.Name,college.CollegeID,college.Name,faculty.StandardID,[standard].Name,grade.GradeID,
  94. faculty.EducationID,education.Name,student.StudentType,studentType.Name,student.SexID,sex.Name,sex.Code having sex.Code='Female'
  95. ) studentFemaleCount
  96. on classCount.CampusID=studentFemaleCount.CampusID
  97. and classCount.CollegeID=studentFemaleCount.CollegeID
  98. and classCount.StandardID=studentFemaleCount.StandardID
  99. and classCount.GradeYear=studentFemaleCount.GradeYear
  100. and classCount.EducationID=studentFemaleCount.EducationID
  101. and classCount.StudentType=studentFemaleCount.StudentType
  102. inner join CF_Schoolyear schoolyear on schoolyear.IsCurrent=1
  103. order by classCount.CampusNo,classCount.CollegeNo