这是我的表结构:-
Table01
ID Name FkID dateTime
1 John 1 2012-06-01
2 Peter 2 2012-06-02
3 Penny 2 2012-06-03
4 Patty 3 2012-06-01
我试过这个查询但是:(
select *
from Table01
where FkID in
(SELECT FkID FROM Table01 GROUP BY FkID HAVING ( COUNT(PkID) < 2 ))
order by dateTime desc
期望的结果:-
1 John 1 2012-06-01
3 Penny 2 2012-06-03
4 Patty 3 2012-06-01
我需要 FkID 的唯一结果,但从重复的 FkID 中我需要按最新的日期时间选择行。请提供任何指导方针。