我不确定您为什么要在内部查询中计算日期。我认为计算开始时间更有意义。这为您提供了每个教师在每个日期上的课程数量的表格:
SELECT COUNT(start_time) AS classes, teacher_no, date
FROM Spanish
GROUP BY tearcher_no, date) AS t
对于特定的 teacher_no X
,您可以按课程数量排序以获得最多课程的日期:
SELECT date
FROM (
SELECT COUNT(start_time) AS classes, date
FROM Spanish
GROUP BY date
WHERE teacher_no = X) AS t
ORDER BY classes DESC
LIMIT 1
最后,您可以获得所有教师的列表,例如
SELECT
a.teacher_no,
(SELECT date
FROM
(SELECT COUNT(b.start_time) AS classes, b.date
FROM Spanish AS b
GROUP BY b.date
WHERE a.teacher_no = b.teacher_no) AS t
ORDER BY classes DESC
LIMIT 1) AS date
FROM Spanish AS a
GROUP BY a.teacher_no