1

我正在尝试计算每年唯一出现的教师。我确信结果不是唯一的。

我的查询

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;

我错过了什么?

谢谢

4

2 回答 2

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;
于 2013-04-16T20:20:50.580 回答
1

你很近。我想这就是你要找的:

SELECT COUNT(*)
FROM
(
SELECT DISTINCT count (tblTeachers.TeacherID) AS uniqueTeacherCount, tblSchoolYears.SchoolYear ...
)
于 2013-04-16T20:24:42.070 回答