日期:2014-05-19  浏览次数:20538 次

数据查询的问题
如果一个数据表里有五个字段,多条数据前3个字段相同,只取一条最新的,请问怎么取??

------解决方案--------------------
eg: tb(a, b, c, d, e)

select * from tb as t
where not exists(select 1 from tb where a = t.a and b = t.b and c = t.c and d < t.d)
------解决方案--------------------
楼上的好想写错了,如果d是时间字段

eg: tb(a, b, c, d, e)

select * from tb as t
where not exists(select 1 from tb where a = t.a and b = t.b and c = t.c and d > t.d)