日期:2014-05-18  浏览次数:20606 次

老问题,关于消除重复记录的问题
field1|field2|field3

客户1   |07-01-12   |事项1
客户1   |07-01-13   |事项2
客户2   |07-01-15   |事项3
客户4   |07-01-16   |事项4

要求只查出:

客户1   |07-01-13   |事项2
客户2   |07-01-15   |事项3
客户4   |07-01-16   |事项4

两条记录,就是只取日期最新的记录,该如何?

------解决方案--------------------

select * from tablename a
where not exists (select 1 from tablename where field1 = a.field1 and field2 > a.field2)
------解决方案--------------------
select * from tbName as A
where not exists(select 1 from tbName where field1=A.field1 and field2> A.field1)