SQL 去除重复记录 只保留重复记录中的一条

select a.*  from USERLOGGERFILTER a where loggertime > '2010-05-31' and loggertime < '2010-06-01' and not exists(select 1 from USERLOGGERFILTER where LoggerPNR=a.LoggerPNR and loggertime<a.loggertime) order by a.airway

条件:

 not exists 不存在于重复的结果集中

loggertime > '2010-05-31' and loggertime < '2010-06-01' 时间范围

loggertime<a.loggertime 表示取相同LoggerPNR 中 LoggerTime最小的一行记录

原文地址:https://www.cnblogs.com/stangray/p/1748882.html