如何选择每个ID

时间:2015-04-26 07:55:03

标签: php mysql

如何选择每个学生的最大学期,如链接图片。

http://i.stack.imgur.com/Ka97X.jpg

enter image description here

2 个答案:

答案 0 :(得分:1)

select s1.* from  student s1
inner join 
(
    select student_id,max(semester) as semester
    from  student group by student_id
) as  s2 
on s1.student_id=s2.student_id and s1.semester=s2.semester

答案 1 :(得分:1)

SELECT *  
FROM STUDENT_SCORE  
GROUP BY student_id  
HAVING MAX(score)

注意:如果您需要将ID重命名为stnd_tbl_nd,则可以使用AS关键字在投影之前或之后执行此操作。