日期:2014-05-16  浏览次数:21903 次

取查询结果重复行的最后一行
例如有张A表
id value
1 44
2 44
3 34
4 56
5 44
6 56
7 34

我需要的结果是取value的值里面对应的最后一行的信息
id value
5 44
7 34
6 56

请问这条SQL语句要怎么写?

------解决方案--------------------
select * from tt a where not exists(select 1 fom tt where a.value=value and a.id<id)
------解决方案--------------------
参考下贴中的多种方法

http://topic.csdn.net/u/20091231/16/2f268740-391e-40f2-a15e-f243b2c925ab.html
[征集]分组取最大N条记录方法征集,及散分....