distinct

Swift 3 - NSFetchRequest Distinct Results

99封情书 提交于 2019-12-05 01:27:10
Any help appreciated. Xcode auto updated to 8... I am Targeting IOS 9.3 Have all of the code converted across but one thing is now breaking, I have tried various suggestions in similar questions! My fetch request that was previously working is now breaking. My goal is to get a distinct list. The app crashes on the line: let results = try context.fetch(fetchRequest) With the error described in the console as: Could not cast value of type 'NSKnownKeysDictionary1' (0x10fd29328) to 'MyApp.BodyType' (0x10eebc820). Here is the function func getBodyTypes() { let context = ad.managedObjectContext let

SQL Query to get common records

不打扰是莪最后的温柔 提交于 2019-12-05 00:55:27
问题 I have a table as below ID Username GroupID 1 venkat 2 2 venkat 3 3 ramu 1 4 ramu 2 Using the sql statement I want to retrieve all username's that are available in both the groupids 2,3 In this case only Venkat is the username that's available in both groupid 2 and 3 Kindly help me 回答1: Try this: SELECT userName FROM tableA WHERE groupId IN (2, 3) GROUP BY userName HAVING COUNT(DISTINCT groupId) = 2; Check the SQL FIDDLE DEMO OUTPUT | USERNAME | |----------| | venkat | 回答2: An alternate

Distinct on specific column in Hive

為{幸葍}努か 提交于 2019-12-05 00:28:11
I am running Hive 071 I have a table, with mulitple rows, with the same column value e.g. x | y | --------- 1 | 2 | 1 | 3 | 1 | 4 | 2 | 2 | 3 | 2 | 3 | 1 | I want to have the x column unique, and remove rows that have the same x val e.g. x | y | --------- 1 | 2 | 2 | 2 | 3 | 2 | or x | y | --------- 1 | 4 | 2 | 2 | 3 | 1 | are both good as distinct works only on the whole rs in hive, I couldn't find a way to do it help please Tx You can use the distinct keyword: SELECT DISTINCT x FROM table try following query to get result : select A.x , A.y from (select x , y , rank() over ( partition by x

Remove duplicate rows in a table having no primary key

蓝咒 提交于 2019-12-05 00:26:49
问题 I have a table item that contains items like name ------ alpha alpha beta charlie charlie In this case how would I delete duplicate rows but one record should remain. The above table does not have any primary key. 回答1: Try this DELETE FROM item WHERE GREATEST(0,@num := IF(NAME = @NAME, @num + 1, 0),LEAST(0, LENGTH(@NAME := NAME)))>0 回答2: Recreate that table: RENAME TABLE `testTable` TO `testTable2`; CREATE TABLE `testTable` SELECT DISTINCT `name` FROM `testTable2`; OR Add UNIQUE INDEX on your

LINQ - writing a query with distinct and orderby

故事扮演 提交于 2019-12-05 00:23:45
I'm quite new to LINQ. Suppose that I had the following table: Incident ID DeviceID Time Info 1 1 5/2/2009 d 2 2 5/3/2009 c 3 2 5/4/2009 b 4 1 5/5/2009 a In LINQ, how could I write a query that finds the most recent and distinct (on Device ID) set of incidents? The result I'd like is this: ID DeviceID Time Info 3 2 5/4/2009 b 4 1 5/5/2009 a Do you have to create an IEqualityComparer to do this? You can get the most recent incidents for each device (this is how I understood your question) with: var query = incidents.GroupBy(incident => incident.DeviceID) .Select(g => g.OrderByDescending

Getting a distinct value across 2 union sql server tables

十年热恋 提交于 2019-12-05 00:21:07
I'm trying to get all distinct values across 2 tables using a union. The idea is to get a count of all unique values in the columnA column without repeats so that I can get a summation of all columns that contain a unique columnA. This is what I tried (sql server express 2008) select count(Distinct ColumnA) from ( select Distinct ColumnA as ColumnA from tableX where x = y union select Distinct ColumnA as ColumnA from tableY where y=z ) SELECT COUNT(distinct tmp.ColumnA) FROM ( (SELECT ColumnA FROM TableX WHERE x=y) UNION (SELECT ColumnA FROM TableY WHERE y=z) ) as tmp The extra distincts on

SQL Select Distinct Values, but order by a different value

♀尐吖头ヾ 提交于 2019-12-05 00:17:59
I want to select all distinct order_ids from my table, and order that list by the date column. Using DISTINCT is of course a query-wide parameter, so trying something like this doesn't work: SELECT DISTINCT(orderId, datetime) FROM table ORDER BY datetime DESC This returns all DISTINCT combinations of the orderId and datetime, so I'm left with multiple orderIds, which I don't want. Therefore I'm thinking that the DISTINCT clause is not the way to go. Does anyone have any suggestions on how I could solve this problem? Thanks! If there are multiple rows for the order, which date do you want to

MongoDB Java driver: distinct with sort

余生长醉 提交于 2019-12-04 23:29:45
问题 Using the MongoDB console I can write a native MongoDB query using distinct key with a sort like this: db.mycollection.distinct('mykey').sort('mykey', 1) Using the Java driver I would expect to be able to write the same query like this: myCollection.distinct("myKey").sort(new BasicDBObject("myKey", 1)); However, this doesn't work because DBCollection#distinct() returns type List and not type DBCursor like DBCollection#find() . How can I write the distinct query with a sort using the Java

C# Distinct去重泛型List

为君一笑 提交于 2019-12-04 23:25:30
List<int> 去重 List<string> 去重 List<T> 去重 1. List<int> 去重 List<int> ilist = new List<int>() { 1, 2, 3, 4, 2, 3 }; ilist = ilist.Distinct().ToList(); foreach (var item in ilist) { Console.WriteLine(item); } 2. List<string> 去重 List<string> strList = new List<string>() { "4", "4", "5", "6", "6" }; strList = strList.Distinct().ToList(); foreach (var item in strList) { Console.WriteLine(item); } 3. List<T> 去重 public class User { public int Id { get; set; } public string Name { get; set; } } //去重类 public class LambdaComparer<T> : IEqualityComparer<T> { private readonly Func<T, T, bool> _lambdaComparer

oracle——distinct的用法

心不动则不痛 提交于 2019-12-04 23:20:51
http://www.cnblogs.com/dogxuefeng/archive/2012/06/21/2557700.html distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用 它来返回不重复记录的条数,而不是用它来返回不重记录的所有值。其原因是distinct只有用二重循环查询来解决,而这样对于一个数据量非常大的站来说,无疑是会直接影响到效率的。 下面先来看看例子: table表 字段1 字段2 id name 1 a 2 b 3 c 4 c 5 b 库结构大概这样,这只是一个简单的例子,实际情况会复杂得多。 比如我想用一条语句查询得到name不重复的所有数据,那就必须使用distinct去掉多余的重复记录。 select distinct name from table 得到的结果是: ---------- name a b c 好像达到效果了,可是,我想要得到的是id值呢?改一下查询语句吧: select distinct name, id from table 结果会是: ---------- id name 1 a 2 b 3 c 4 c 5 b distinct怎么没起作用?作用是起了的,不过他同时作用了两个字段,也就是必须得id与name都相同的才会被排除。。。。。。。 我们再改改查询语句: select id, distinct name