distinct

Mysql Select rows with same values in one column and different in another

给你一囗甜甜゛ 提交于 2019-12-04 04:38:37
I'd really appreciate it if someone could validate my SQL query. For the following dataset: MD5 UserPK CategoryPK ADCDE 1 7 ADCDE 1 4 ADCDE 1 7 dffrf 1 7 dffrf 2 7 dffrf 2 6 dffrf 1 1 I'd like to select MD5 and CategoryPK where two or more rows exist with identical MD5 values, identical CatgegoryPK and two or more DIFFERENT UserPK values. In other words, I'd like to know the MD5 and categoryPK of all records where two or more different users (UserPK) have assigned the same category (UserPK) to the same file (Md5). I'm not interested in records the same user has assigned the category to

Filter realm objects to only get one (distinct) object by attribute

独自空忆成欢 提交于 2019-12-04 04:03:28
问题 Let me explain first cause title may be a bit confusing. Say I have this realm objects of type Movie: Movie1(id: 0, genre: "horror") Movie2(id: 1, genre: "horror") Movie3(id: 3, genre: "sci-fi") What I need to do is get the first for every genre (in this case Movie1 and Movie3 ) I'd like to do it w/o loops using only realm + NSPredicate , so the performance is better, but I'm a bit stuck there... So far what I got is this: Realm().objects(Movie.self).sorted(byKeyPath: id, ascending: true)

Count number of distinct rows for multiple values

梦想的初衷 提交于 2019-12-04 03:53:37
问题 Let's consider this table specifing how many times a person bought a property. +--------+----------+ | user | property | +--------+----------+ | john | car | | john | car | | john | house | | peter | car | | peter | car | | amanda | house | | amanda | house | +--------+----------+ I need to know how many times a car was bought once, how many times a house was bought once, etc. Something like this: +----------+---+---+ | property | 1 | 2 | +----------+---+---+ | cars | 4 | 2 | | house | 3 | 1

How to count occurrences of unique values in Dictionary?

空扰寡人 提交于 2019-12-04 03:47:01
I have a Dictionary with doubles as values and strings as keys. I want to count occurrences of each value in this Dictionary and I want to know this value (that is for instance repeated). for instance: key1, 2 key2, 2 key3, 3 key4, 2 key5, 5 key6, 5 I want to get a list: 2 - 3 (times) 3 - 1 (once) 5 - 2 (twice) How can I do it? The first thing to note, is that you don't actually care about the keys of the dictionary. Step one therefore is to ignore them as irrelevant to the task in hand. We're going to work with the Values property of the dictionary, and the work is much the same as for any

Using Distinct with LINQ and Objects

萝らか妹 提交于 2019-12-03 23:18:29
Until recently, I was using a Distinct in LINQ to select a distinct category (an enum) from a table. This was working fine. I now need to have it distinct on a class containing a category and country (both enums). The Distinct isn't working now. What am I doing wrong? Stilgar I believe this post explains your problem: http://blog.jordanterrell.com/post/LINQ-Distinct()-does-not-work-as-expected.aspx The content of the above link can be summed up by saying that the Distinct() method can be replaced by doing the following. var distinctItems = items .GroupBy(x => x.PropertyToCompare) .Select(x =>

Django query with distinct and order_by

放肆的年华 提交于 2019-12-03 23:04:00
I have two models class Employer(models.Model): name = models.CharField(max_length=300, blank=False) id = models.IntegerField() status = models.IntegerField() eminence = models.IntegerField(null=False,default=4) class JobTitle(models.Model) name = models.CharField(max_length=300, blank=False) employer = models.ForeignKey(Employer,unique=False,null=True) activatedate = models.DateTimeField(default=datetime.datetime.now) I need all employers in the order of whose jobtitle activated last. Employer.objects.filter(status=1).order_by('eminence','-jobtitle__activatedate') This query gives me what I

Does SQL Server support IS DISTINCT FROM clause?

天涯浪子 提交于 2019-12-03 22:53:57
Does SQL Server support IS DISTINCT FROM statement which is SQL:1999 standard? E.g. the query SELECT * FROM Bugs WHERE assigned_to IS NULL OR assigned_to <> 1; can be rewritten using IS DISTINCT FROM SELECT * FROM Bugs WHERE assigned_to IS DISTINCT FROM 1; No, it doesn't. The following SO question explains how to rewrite them into equivalent (but more verbose) SQL Server expressions: How to rewrite IS DISTINCT FROM and IS NOT DISTINCT FROM? There's also a Uservoice entry for this issue, where you can vote for inclusion in the next release: Add language and optimizer support for ISO <distinct

Linq to SQL: DISTINCT with Anonymous Types

£可爱£侵袭症+ 提交于 2019-12-03 21:47:03
Given this code: dgIPs.DataSource = from act in Master.dc.Activities where act.Session.UID == Master.u.ID select new { Address = act.Session.IP.Address, Domain = act.Session.IP.Domain, FirstAccess = act.Session.IP.FirstAccess, LastAccess = act.Session.IP.LastAccess, IsSpider = act.Session.IP.isSpider, NumberProblems = act.Session.IP.NumProblems, NumberSessions = act.Session.IP.Sessions.Count() }; How do I pull the Distinct() based on distinct Address only? That is, if I simply add Distinct(), it evaluates the whole row as being distinct and thusly fails to find any duplicates. I want to return

How to select DISTINCT rows without having the ORDER BY field selected

戏子无情 提交于 2019-12-03 21:45:33
问题 So I have two tables students (PK sID) and mentors (PK pID). This query SELECT s.pID FROM students s JOIN mentors m ON s.pID = m.pID WHERE m.tags LIKE '%a%' ORDER BY s.sID DESC; delivers this result pID ------------- 9 9 3 9 3 9 9 9 10 9 3 10 etc... I am trying to get a list of distinct mentor ID's with this ordering so I am looking for the SQL to produce pID ------------- 9 3 10 If I simply insert a DISTINCT in the SELECT clause I get an unexpected result of 10, 9, 3 (wrong order). Any help

Using SQL query to find details of customers who ordered > x types of products

余生颓废 提交于 2019-12-03 21:45:00
问题 Please note that I have seen a similar query here, but think my query is different enough to merit a separate question. Suppose that there is a database with the following tables: customer_table with customer_ID (key field), customer_name orders_table with order_ID (key field), customer_ID, product_ID Now suppose I would like to find the names of all the customers who have ordered more than 10 different types of product, and the number of types of products they ordered. Multiple orders of the