读书人

数据查询的有关问题

发布时间: 2012-01-11 22:28:46 作者: rapoo

数据查询的问题
如果一个数据表里有五个字段,多条数据前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)


读书人网 >SQL Server

热点推荐