public static List removeDuplicateWithOrder(List list) { Set set = new HashSet(); List newList = new ArrayList(); for (Iterator iter = list.iterator(); iter.hasNext();) { Object element = iter.next(); if (set.add(element)){ newList.add(element); } }
为了去重复,写了一个通用的比较容器类,可以用在需要比较的地方,且支持Lamda表达式,代码如下: public class DataComparer<T>:IEqualityComparer<T> where T:class { private Func<T, T, bool> _compareFunc; public DataComparer(Func<T,T,bool> compareFunc) { this._compareFunc = compare
postgre去重复记录,主要用到row定位的一个系统表示 “ctid”,能查出纯净的不重复的记录,那要删掉重复值也就容易了,自己去折腾吧. 我所涉及的是得到不重复的记录,就一句话: select ctid, * from table007 where ctid in (select min(ctid) from table007 group by att001,att002,att003);
用distinct关键字只能过滤查询字段中所有记录相同的(记录集相同),而如果要指定一个字段却没有效果,另外distinct关键字会排序,效率很低 . select distinct name from t1 能消除重复记录,但只能取一个字段,现在要同时取id,name这2个字段的值. select distinct id,name from t1 可以取多个字段,但只能消除这2个字段值全部相同的记录 所以用distinct达不到想要的效果,用group by 可以解决这个问题. 例如要显示