如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中. 错误的写法:select distinct top 100 userphone from message order by proxyid desc 正确的写法:select distinct top 100 userphone,proxyid from message order by proxyid desc…
问题引出:在实际中遇到一个问题,要进行集合去重,集合内存储的是引用类型,需要根据id进行去重.这个时候linq 的distinct 就不够用了,对于引用类型,它直接比较地址.测试数据如下: class Person { public int ID { get; set; } public string Name { get; set; } } List<Person> list = new List<Person>() { new Person(){ID=1,Name="…
具体错误提示是:django.db.utils.NotSupportedError: DISTINCT ON fields is not supported by this database backend 刚好遇到mysql数据库查重,使用distinct方法来做去重查询,结果遇到这个错误.先看一下distinct的源码: def distinct(self, *field_names): """ Return a new QuerySet instance that wi…