distinct

Distinct in Entity framework

£可爱£侵袭症+ 提交于 2019-12-03 13:37:45
I have a List of objects that some of them have the same Ids, so I would like to remove those elements that are duplicated. I tried with something like this: List<post> posts = postsFromDatabase.Distinct().ToList(); But it doesn't work! So I wrote this method in order to avoid the duplicates: public List<Post> PostWithOutDuplicates(List<Post> posts) { List<Post> postWithOutInclude = new List<Post>(); var noDupes = posts.Select(x => x.Id).Distinct(); if (noDupes.Count() < posts.Count) { foreach (int idPost in noDupes) { postWithOutInclude.Add(posts.Where(x => x.Id == idPost).First()); } return

SELECT COUNT(DISTINCT [name]) from several tables

只谈情不闲聊 提交于 2019-12-03 13:25:50
问题 I can perform the following SQL Server selection of distinct (or non-repeating names) from a column in one table like so: SELECT COUNT(DISTINCT [Name]) FROM [MyTable] But what if I have more than one table (all these tables contain the name field called [Name]) and I need to know the count of non-repeating names in two or more tables. If I run something like this: SELECT COUNT(DISTINCT [Name]) FROM [MyTable1], [MyTable2], [MyTable3] I get an error, "Ambiguous column name 'Name'". PS. All

操作数据库

左心房为你撑大大i 提交于 2019-12-03 13:08:29
数据库 一,数据库简介 1.数据库的起源: 随着互联网时代的到来,需要持久化数据呈现井喷式发展,常规的 io操作虽然 可以满足持久化的需求,但是,对于持久化的目的,对数据的操纵,显然力不从心, 且操作的复杂度很大,不利于大规模的发展,审时度势,数据库应运而生。 2.数据库的定义:数据库(Database)是按照数据结构来组织、存储和管理数据的仓库;随着信息 技术和市场的发展,数据管理不再仅仅是存储和管理数据,而转变成用户所需要的各 种数据管理的方式。数据库有很多种类型,从最简单的存储有各种数据的表格到能够 进行海量数据存储的大型数据库系统都在各个方面得到了广泛的应用。 数据库现在已经成为数据管理的重要技术,也是计算机的重要分支。由于数据 库具有数据结构化,最低冗余度、较高的程序与数据独立性,易于扩展、易于编制应 用程序等优点,较大的信息系统都是建立在数据库设计之上的。数据库的运用从一般 管理扩大到计算机辅助技术、人工智能以及科技计算等领域。 随着数据库技术的发展,计算机技术也随着得到了很大的发展,数据库为我们 提供了可以快速存储以及检索的便利,它也为近几年软件可以如此普及贡献不小的力 量 3.常用的数据库有:MySQL,Oracle,DB2 4. 数据库管理系统(Database Management System)是一种操纵和管理数据库的大 型软件,用于建立、使用和维护数据库

SELECT DISTINCT cql ignores WHERE clause

被刻印的时光 ゝ 提交于 2019-12-03 11:48:59
Executing two identical requests but the DISTINCT keyword gives unexpected results. Without the keyword, the result is ok but with DISTINCT, it looks like the where clause is ignored. Why ? Cqlsh version: Connected to Test Cluster at localhost:9160. [cqlsh 4.1.1 | Cassandra 2.0.6 | CQL spec 3.1.1 | Thrift protocol 19.39.0] Table considered: DESCRIBE TABLE events; CREATE TABLE events ( userid uuid, "timestamp" timestamp, event_type text, data text, PRIMARY KEY (userid, "timestamp", event_type) ) WITH bloom_filter_fp_chance=0.010000 AND caching='KEYS_ONLY' AND comment='' AND dclocal_read_repair

Django Models - SELECT DISTINCT(foo) FROM table is too slow

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a MySQL table with 13M rows. I can query the db directly as SELECT DISTINCT(refdate) FROM myTable The query takes 0.15 seconds and is great. The equivalent table defined as a Django model and queried as myTable.objects.values(`refdate`).distinct() takes a very long time. Is it because there are too many items in the list before distinct() . How do I do this in a manner that doesn't bring everything down? 回答1: Thank you @solarissmoke for the pointer to connection.queries . I was expecting to see SELECT DISTINCT refdate FROM myTable

Get density of messages on distinct ID&#039;s

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Imagine that there is 10 houses, where there can be one to an infinite number of persons. Each of those persons sends a number of messages, containing their userid and the house number. This can be from 1 to infinite number of messages. I want to know the average number of messages that is sent by each person, for each house, to later plot which house got the largest number of average messages. Now, that I've explained conceptually, the houses aren't houses, but latitudes, from f.ex -90 to -89 etc. And that a person can send messages from

Implementing IEqualityComparer<T> on an object with two properties in C#

与世无争的帅哥 提交于 2019-12-03 10:20:00
问题 I have a case where I need to grab a bunch of items on distinct, but my source is a collection of objects with two properties, like this: public class SkillRequirement { public string Skill { get; set; } public string Requirement { get; set; } } I try to get a collection as follows: SkillRequirementComparer sCom = new SkillRequirementComparer(); var distinct_list = source.Distinct(sCom); I tried to implement an IEqualityComparer<T> for this, but I fell stumped at the GetHashCode() method. The

distinct关键字

让人想犯罪 __ 提交于 2019-12-03 09:18:18
对于distinct关键字,distinct关键字应用于所有列而不仅是前置它的列,如果给出多个列,将会比较两个列。 这是完整表, 首先是select distinct username from user;  看看结果 可以看到已经去重了, 现在是select distinct username,sex from user; 看看结果 可以看到这个去重是先比较username,如果相同再比较sex,如果都相同就去重,不然不会去重。 来源: https://www.cnblogs.com/cold-windy/p/11785211.html

Xslt distinct select / Group by

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What i have done so fare is to go through all distict frontendGroupIds. What i would like to do now is to do a count of all the distict caseIds for each distict frontendGroupId but i cant seem to make that work. Can someone help me here plz? 回答1: You were close: This results in: 2336 - 2 2337 - 3 EDIT - Oh, I see you want the distinct count within the group. This would be: Which looks (admittedly) a bit frightening. It outputs: 2336 - 1 2337 - 2 The core expression: count( key('kStatisticItemByGroup', @frontendGroupId)[ count( . | key(

PostGres Error When Using Distinct : postgres ERROR: could not identify an ordering operator for type record

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: ** EDIT ** Nevermind, just needed to take out the parens... I get this error: ERROR: could not identify an ordering operator for type record when trying to use DISTINCT Here's the query: select DISTINCT(g.fielda, g.fieldb, r.type) from fields g LEFT JOIN types r ON g.id = r.id; And the errors: ERROR: could not identify an ordering operator for type record HINT: Use an explicit ordering operator or modify the query. ********** Error ********** ERROR: could not identify an ordering operator for type record SQL state: 42883 Hint: Use an