mysql查询(分组依据?与众不同?)

时间:2018-12-01 15:05:35

标签: mysql

表格行

no | f_member_id | f_teacher_id | f_class_date
 1 | jenny       | teacher_a    | 2017-12-03
 3 | jenny       | teacher_a    | 2017-12-05
 2 | jenny       | teacher_a    | 2017-12-04
 4 | tom         | teacher_a    | 2017-11-27
 5 | tom         | teacher_a    | 2017-11-28

“ teacher_a”需要看到这样的结果。

---------------
jenny | teacher_a | 2017-12-05
tom   | teacher_a | 2017-11-28

------

*** Teacher_a所在班级的学生姓名的最近上课日期。

我这样查询。没用。

 SELECT distinct(f_member_id), f_class_date 
 FROM `classroom` where f_teacher_id='teacher' 
 group by f_member_id 
 order by f_class_date desc

1 个答案:

答案 0 :(得分:0)

select f_member_id, f_teacher_id ,max(f_class_date) from table group by f_member_id,f_teacher_id;