Count distinct value pairs in multiple columns in SQL
To get a count of the number of unique combinations of id, name and address: SELECT Count(*) FROM ( SELECT DISTINCT id , name , address FROM your_table ) As distinctified
To get a count of the number of unique combinations of id, name and address: SELECT Count(*) FROM ( SELECT DISTINCT id , name , address FROM your_table ) As distinctified
Use this: items.Select(i => i.Value).Distinct().Count()
Just list multiple columns in the GROUP BY clause. SELECT computer, user, count(*) AS count FROM login GROUP BY computer, user
Use: SELECT p.upc, p.name, ph.price, ph.date FROM PRODUCT p LEFT JOIN PRICE_H ph ON ph.product_id = p.id JOIN (SELECT a.product_id, MAX(a.date) AS max_date FROM PRICE_H a GROUP BY a.product_id) x ON x.product_id = ph.product_id AND x.max_date = ph.date
I haven’t tested it, so the syntax might not be perfect, but what about something like this : select name, count(*) as frequency from your_table group by name order by count(*) desc Should give you unique names and the corresponding number of times each name appears in the table, ordered by that number.
The exact query can be produced using the tuple_() construct: session.query( func.count(distinct(tuple_(Hit.ip_address, Hit.user_agent)))).scalar()
var noticesGrouped = notices.GroupBy(n => n.Name). Select(group => new { NoticeName = group.Key, Notices = group.ToList(), Count = group.Count() });
It’s better to include code in your question, rather than ambiguous text data, so that we are all working with the same data. Here is the sample schema and data I have assumed: CREATE TABLE tbl_data ( id INT NOT NULL, code_1 CHAR(2), code_2 CHAR(2) ); INSERT INTO tbl_data ( id, code_1, code_2 ) VALUES … Read more
No. You cannot specify which exact field you need to distinct with. It only works with the whole row. As of your problem – just make your query a subquery and in outer one GROUP BY user_id SELECT * FROM (SELECT a.user_id,a.updatecontents as city,b.country FROM userprofiletemp AS a LEFT JOIN userattributes AS b ON a.user_id=b.user_id … Read more
You can just do: db.collection.distinct(“children.child_name”); In your case it returns: [ “John”, “Anna”, “Kevin” ]