我正在尝试计算每年独特的老师身份。我相信结果不是唯一的。
我的查询
SELECT DISTINCT count (tblTeachers.TeacherID) AS uniqueTeacherCount, tblSchoolYears.SchoolYear
FROM tblTeachers INNER JOIN tblTeacher_Building
.
.
GROUP BY tblSchoolYears.SchoolYear
ORDER BY tblSchoolYears.SchoolYear DESC;
结果(计算TeacherID的副本)
我也试过
SELECT COUNT(DISTINCT tblTeachers.TeacherID) AS uniqueTeacherCount, tblSchoolYears.SchoolYear
FROM tblTeachers INNER JOIN tblTeacher_Building
.
.
GROUP BY tblSchoolYears.SchoolYear
ORDER BY tblSchoolYears.SchoolYear DESC;
我错过了什么?
谢谢
答案 0 :(得分:3)
Select Count(TeacherID) AS uniqueTeacherCount,SchoolYear
from
(
SELECT DISTINCT tblTeachers.TeacherID, tblSchoolYears.SchoolYear
FROM tblTeachers INNER JOIN tblTeacher_Building
.
.
) hlp
GROUP BY SchoolYear
ORDER BY SchoolYear DESC;
答案 1 :(得分:1)
你很亲密。我想这就是你要找的东西:
SELECT COUNT(*)
FROM
(
SELECT DISTINCT count (tblTeachers.TeacherID) AS uniqueTeacherCount, tblSchoolYears.SchoolYear ...
)