distinct

SELECT COUNT(DISTINCT [name]) from several tables

杀马特。学长 韩版系。学妹 提交于 2019-12-03 03:26:32
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 three tables [MyTable1], [MyTable2], [MyTable3] are a product of a previous selection. After the

Select random row per distinct field value?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a MySQL query that results in something like this: person | some_info ================== bob | pphsmbf24 bob | rz72nixdy bob | rbqqarywk john | kif9adxxn john | 77tp431p4 john | hx4t0e76j john | 4yiomqv4i alex | n25pz8z83 alex | orq9w7c24 alex | beuz1p133 etc... (This is just a simplified example. In reality there are about 5000 rows in my results). What I need to do is go through each person in the list (bob, john, alex, etc...) and pull out a row from their set of results. The row I pull out is sort of random but sort of also based

How to execute UNION without sorting? (SQL)

两盒软妹~` 提交于 2019-12-03 03:08:12
问题 UNION joins two results and remove duplicates, while UNION ALL does not remove duplicates. UNION also sort the final output. What I want is the UNION ALL without duplicates and without the sort. Is that possible? The reason for this is that I want the result of the first query to be on top of the final result, and the second query at the bottom (and each sorted as if they where run individually). 回答1: I notice this question gets quite a lot of views so I'll first address a question you didn't

How does Distinct() function work in Spark?

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm a newbie to Apache Spark and was learning basic functionalities. Had a small doubt.Suppose I have an RDD of tuples (key, value) and wanted to obtain some unique ones out of them. I use distinct() function. I'm wondering on what basis does the function consider that tuples as disparate..? Is it based on the keys, or values, or both? 回答1: .distinct() is definitely doing a shuffle across partitions. To see more of what's happening, run a .toDebugString on your RDD. val hashPart = new HashPartitioner( ) val myRDDPreStep = val myRDD =

Distinct implementations for pure virtual functions with same name [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Possible Duplicate: Inherit interfaces which share a method name I have two base classes I1 and I2 with pure virtual functions void R() = 0; . I want the derived class IImpl to inherit from I1 and I2 and to have distinct implementations for I1::R() and I2::R() . The code below compiles and works in MS VS 2005 and 2010. I compile with Language Extension disabled and on warning level 4. There are no warnings and no errors. I tried the same code in gcc 4.2. It does not compile. GCC reports an error: error: cannot define member function 'I1::R'

How to do a distinct count in JPA critera API?

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like to do this but with the criteria API instead: select count(distinct e) from Event e, IN(e.userAccessPermissions) p where p.principal = :principal and p.permission in (:permissions) Any ideas? 回答1: You can use countDistinct on CriteriaBuilder criteriaQuery.select(criteriaBuilder.countDistinct(entityRoot)) 回答2: Like this? Criteria crit = session.createCriteria(Event.class): crit.createAlias("userAccessPermissions", "p"); crit.add(Restrictions.eq("p.principal", principal); crit.add(Restrictions.in("p.permission", permissions); crit

pymongo- How can I have distinct values for a field along with other query parameters

匿名 (未验证) 提交于 2019-12-03 02:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using pymongo and want to have distinct values for a field such that I can also pass other query parameters. For example, I have entries like: { id = "my_id1" tags: [tag1, tag2, tag3], category: "movie", } { id = "my_id2" tags: [tag3, tag6, tag9], category: "tv", } { id = "my_id3" tags: [tag2, tag6, tag8], category: "movie", } So I want to have all distinct tags under movie category. Can anyone please guide how can I achive this using pymongo. In mongo javascript shell, I issued db.mycoll.distinct('tags', {category: "movie"}) and it

LINQ Select Distinct Count in Lambda form

匿名 (未验证) 提交于 2019-12-03 02:54:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Given a linq expression of an object collection 'items' such as this: var total = (from item in items select item.Value).Distinct().Count() Is it possible to convert this to use linq functions/lambdas: items.Select(???).Distinct().Count() 回答1: Use this: items.Select(i => i.Value).Distinct().Count() 回答2: It must be possible, since behind the scenes, LINQ is translated to lambdas and expression trees (at least LINQ to objects) In your case the ??? part would be item => item.Value , i.e. for item , output item.value . So, the whole expression

MySQL: Count occurrences of distinct values

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to find a MySQL query that will find distinct values in a particular field, count the number of occurrences of that value and then order the results by the count. example db id name ----- ------ 1 Mark 2 Mike 3 Paul 4 Mike 5 Mike 6 John 7 Mark expected result name count ----- ----- Mike 3 Mark 2 Paul 1 John 1 Thanks 回答1: SELECT name,COUNT(*) as count FROM tablename GROUP BY name ORDER BY count DESC; 回答2: what about something like this : select name, count(*) as num from your_table group by name order by count(*) desc ie, you are

Django order_by() filter with distinct()

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I make an order_by like this .... p = Product.objects.filter(vendornumber='403516006')\ .order_by('-created').distinct('vendor__name') The problem is that I have multiple vendors with the same name, and I only want the latest product by the vendor .. Hope it makes sense? I got this DB error: SELECT DISTINCT ON expressions must match initial ORDER BY expressions LINE 1: SELECT DISTINCT ON ("search_vendor"."name") "search_product"... 回答1: Based on your error message and this other question , it seems to me this would fix it: p =