您的位置:首页 > 数据库

数据库取得最新的不重复数据(亲自实践)

2013-08-23 16:33 99 查看
数据库中有个简单的表,两个字段:num 和 endDate

数据Sample如下:

test

numendDate
012013/8/1
022013/8/2
012013/8/3
032013/8/4
现在想取得每个num的最新endDate数据

SQL语句如下:

select * from test as a

where exists

(select 1 from test where num=a.num group by num having max(endDate)=a.endDate)

order by num;

结果如下:

查询1

numendDate
012013/8/3
022013/8/2
032013/8/4
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐