distinct

Counting Using Group By Linq

好久不见. 提交于 2019-12-04 09:06:57
问题 I have an object that looks like this: Notice { string Name, string Address } In a List<Notice> I want to output All distinct Name and how many times the particular appears in the collection. For example: Notice1.Name="Travel" Notice2.Name="Travel" Notice3.Name="PTO" Notice4.Name="Direct" I want the output Travel - 2 PTO - 1 Direct -1 I can get the distinct names fine with this code but I can't seem to get the counts all in 1 linq statement theNoticeNames= theData.Notices.Select(c => c

Mysql DISTINCT not working if I add another column

喜夏-厌秋 提交于 2019-12-04 07:36:47
问题 mysql> select DISTINCT title, id from myadmins; +------+------------+ | id | title | +------+------------+ | 1 | admin | | 2 | stack | | 3 | jeff | | 4 | admin | | 5 | stack | +------+------------+ 1 row in set (0.00 sec) EDIT What I want is not repeting the title column +------+------------+ | id | title | +------+------------+ | 2 | stack | | 3 | jeff | | 4 | admin | +------+------------+ 1 row in set (0.00 sec) 回答1: DISTINCT applies to the entire row of data. Since the ID is different on

django comment framework: distinct() does not work?

不打扰是莪最后的温柔 提交于 2019-12-04 06:11:48
Running distinct() on any field of the comment model always returns all the records, Comment.objects.values('user').distinct() [{'user': 1}, {'user': 0}, {'user': 0}, {'user': 0}, {'user': 0}, {'user': 1}, {'user': 1}, {'user': 1}, {'user': 1}] Comment.objects.values('ip_address').distinct() [{'ip_address': u'127.0.0.1'},{'ip_address': u'192.168.0.180'}, {'ip_address':u'192.168.0.180'}, {'ip_address': u'192.168.0.180'}, {'ip_address': u'192.168.0. 180'}, {'ip_address': u'192.168.0.180'}, {'ip_address': u'192.168.0.180'}, {'ip_address': u'192.168.0.180'}, {'ip_address': u'192.168.0.180'}] Why

ORA-30926 - Merge state

回眸只為那壹抹淺笑 提交于 2019-12-04 06:11:46
问题 I am getting an ORA-30926 error. I researched this and found that this is usually caused by duplicates in the query specified in the USING clause. The problem is I am intially removing duplicates and storing in a temperory table ( temp_distinct ) which in turn I am referring to in the MERGE . Here is my code snippet: MERGE INTO name_test nt USING (select name from temp_distinct) s ON (1=1) WHEN MATCHED THEN UPDATE SET nt.fn = s.name, nt.LN = s.name Here is the structure of my tables: NAME

Returning distinct values from foreach loop in PHP?

倖福魔咒の 提交于 2019-12-04 06:08:33
I have a foreach loop which echo 's each of the property types in my search results. The code is as follows: <?php foreach($search_results as $filter_result) { echo $filter_result['property_type']; } ?> The above code returns: house house house house flat flat flat I would like to do something similar to the MySQL 'distinct', but I am not sure how to do it on a foreach statement. I want the above code to return: house flat Not repeat every item each time. How can I do this? Try with: $property_types = array(); foreach($search_results_unique as $filter_result){ if ( in_array($filter_result[

Selecting distinct pair mysql

穿精又带淫゛_ 提交于 2019-12-04 06:08:00
I would like to select the rows that has the same values across column A and column B. For example if my table is A B 1 2 3 4 1 2 4 5 The output should be A B 1 2 A. Select Distinct A,B from table selects all the values in the table. B. Select Distinct (A,B) from table tells me that Distinct function can take only one value. C. Select A,B from table group by A,B Selects all the values in the table (Similar to A). The question is similar to Selecting Distinct combinations. but the answer suggested there doesn't work. You want only the rows which have duplicates. You can use the HAVING clause to

【Oracle】SQL的一些关键字

空扰寡人 提交于 2019-12-04 05:52:37
1. distinct 关键词 DISTINCT 用于返回唯一不同的值; 只可以在select中使用; 既可以对一列,也可以对多列使用; distinct对NULL是不进行过滤的,即返回的结果中是包含NULL值的; 与ALL不能同时使用(select all order_name from prd_order); 可以与*一起使用,表示的是全部列; select distinct order_name from prd_order; select distinct order_num, order_name from prd_order; select distinct * from prd_order; 来源: https://www.cnblogs.com/myitnews/p/11834134.html

Mongo Distinct Aggegation

十年热恋 提交于 2019-12-04 05:01:12
问题 I'm trying to use the aggregation framework to perform group counts in mongo but the results are not exactly as expected. Consider the collection bellow $people->insert(array("user_id" => "1", "day" => "Monday", 'age' => 18)); $people->insert(array("user_id" => "3", "day" => "Monday", 'age' => 24)); $people->insert(array("user_id" => "1", "day" => "Monday", 'age' => 18)); $people->insert(array("user_id" => "1", "day" => "Monday", 'age' => 18)); $people->insert(array("user_id" => "2", "day" =>

Retrieving distinct records based on a column on Django

痞子三分冷 提交于 2019-12-04 04:55:26
I need to retrieve a list of records for the following table with distinct values in regards to name: Class C: name value A ------------------ 10 A ------------------ 20 A ------------------ 20 B ------------------ 50 C ------------------ 20 D ------------------ 10 B ------------------ 10 A ------------------ 30 I need to get rid of all the duplicate values for name and only show the following: name value A ------------------ 30 B ------------------ 10 C ------------------ 20 D ------------------ 10 As you can see, it almost looks like a python set. I can probably generate the set using Python

Select Count(Distinct Value) returns 1

一个人想着一个人 提交于 2019-12-04 04:41:02
I'm designing a query in SSMS 2005 which looks something like this: SELECT COUNT(DISTINCT ColumnName) FROM Table WHERE ColumnName IS NOT NULL When I run the query with COUNT() it returns the value 1. When I run it without COUNT(), SSMS reports the correct value eg 212 records. The column in question is of datatype numeric(16, 0). For those who might ask, the query in full is: SELECT COUNT(DISTINCT O_ID) FROM vEmployers INNER JOIN vEnrolment ON O_ID = E_EnrolmentEmployer WHERE E_START >= '01-AUG-2008' AND E_START < '01-AUG-2009' AND O_ID IS NOT NULL AND O_ID IN ( SELECT O_ID FROM vEmployers