首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

数据查询的有关问题

2012-01-11 
数据查询的问题如果一个数据表里有五个字段,多条数据前3个字段相同,只取一条最新的,请问怎么取??[解决办法

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


热点排行