我有两张桌子:
teachers (teacher_id,teacher_name)
courses (teacher_id,course_id)
我需要显示教师的姓名,教授最多课程数:
mysql> select teacher.teacher_name,tmp1.teacher_id,tmp1.cnt from (select max(tm p.cnt) as tmpMax from (select teacher_id,count(teacher_id) as cnt from course g roup by teacher_id) as tmp) as tmp2, (select teacher_id,count(teacher_id) as cnt from courses by teacher_id) as tmp1,teachers where tmp1.cnt = tmp2.tmpMax and teacher.teacher_id = tmp1.teacher_id;
我想出了上面的查询。这个问题有更简单的查询吗?