我有这样一张桌子:
entry_time student class grade
------------------------------
1433793600 Dave 1 A
1433793600 Sue 1 B
1434994097 Dave 1 C
1434994097 Sue 1 B
我使用此命令:
SELECT *, MAX(entry_time) from records GROUP BY student
我为每个学生而不是最后一个学生获得了第一个记录。我尝试过使用MIN(entry_time)并得到同样的东西。
答案 0 :(得分:0)
使用此查询尝试:
select * from
record r
where entry_time in
(select max(entry_time) from record s where s.student = r.student group by student)
答案 1 :(得分:-1)
尝试此查询
select *,mdate from records a
join (
SELECT student, MAX(entry_time) as mdate
from records GROUP BY student) a on a.student=b.student and a.entry_time=b.entry_time
答案 2 :(得分:-1)
尝试下面获取最新行(您的查询将仅提供日期列中的最新日期,但不提供最新记录) -
select student,grade,entry_time
from (select student,grade,entry_time from records order by entry_time desc) a group by student