distinct

Preserve the order of distinct inside string_agg

一世执手 提交于 2019-12-12 13:19:34
问题 My SQL function: with recursive locpais as ( select l.id, l.nome, l.tipo tid, lp.pai from loc l left join locpai lp on lp.loc = l.id where l.id = 12554 union select l.id, l.nome, l.tipo tid, lp.pai from loc l left join locpai lp on lp.loc = l.id join locpais p on (l.id = p.pai) ) select * from locpais gives me 12554 | PARNA Pico da Neblina | 9 | 1564 12554 | PARNA Pico da Neblina | 9 | 1547 1547 | São Gabriel da Cachoeira | 8 | 1400 1564 | Santa Isabel do Rio Negro | 8 | 1400 1400 | RIO NEGRO

JPA - getting distinct value from one column

我们两清 提交于 2019-12-12 12:53:22
问题 I have an entity that has few fields. One of them is city name. Now I want to get list of all distinct cities from that table. How can I archive that. I tried using DISTINCT keyword, but it doesn't work. I'm using Hibernate as JPA provider but I would like to get it in pure JPA Query. 回答1: Have you tried: SELECT DISTINCT t.city FROM MyTable t 来源: https://stackoverflow.com/questions/3600870/jpa-getting-distinct-value-from-one-column

Get list of distinct values in List<T> in c#

為{幸葍}努か 提交于 2019-12-12 12:17:15
问题 So, say I have something like the following: public class Element { public int ID; public int Type; public Properties prorerty; ... } and public class Properties { public int Id; public string Property; ... } and I have a list of these: List Elements = new List(); What would be the cleanest way to get a list of all distinct values in the prorerty column in Element class? I mean, I could iterate through the list and add all values that aren't duplicates to another list of strings, but this

MySQL select distinct products from 3 tables

狂风中的少年 提交于 2019-12-12 10:57:32
问题 MySQL select from 3 tables. I have these 5 tables: CREATE TABLE `category` ( `c_id` int(6) NOT NULL AUTO_INCREMENT, `name` varchar(40) NOT NULL, PRIMARY KEY (c_id) ); CREATE TABLE `product` ( `p_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(40) NOT NULL, `brand` varchar(30) NOT NULL, `image_path` varchar(100) DEFAULT NULL, PRIMARY KEY (p_id) ); CREATE TABLE `shop` ( `s_id` int(6) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `country` varchar(30) NOT NULL, `province` varchar(30)

SELECT several records for each DISTINCT one in a single query

烈酒焚心 提交于 2019-12-12 10:55:09
问题 I need to select several rows per each distinct record. Pretty much something like asked here Select first n records for each distinct ID in SQL Server 2008, although I use MySQL. The purpose can be achieved by running 21 queries in this case: 1 general and 20 to get the subrecords, i.e. something like this: SELECT DISTINCT `user_id` FROM `posts` WHERE `deleted` = '0' ORDER BY `user_id` ASC LIMIT 20 ... to select all rows needed, and then SELECT * FROM `posts` WHERE `deleted` = '0' AND `user

Counting unique elements in Scheme

痞子三分冷 提交于 2019-12-12 10:09:32
问题 Write a recursive Scheme procedure count-dist elements that takes a list with duplicate elements and returns the number of distinct elements in the list. This is my code, but it is not working correctly. Please help! Thanks!! (define (count-dist-elements lis) (cond ((null? lis) 0) ((null? (cdr lis))0) ((member (car lis)(cdr lis))) (else(+ 1(count-dist-elements (cdr lis)))))) p/s: let it be (count-dist-elements '(1 2 1 1 2 3 4 5 5 6 6 7 7 8 8 8 9)) 回答1: It looks like you're getting pretty

How to extract distinct values from a mongo database using Waterline and Sails.js (version 0.10)?

╄→гoц情女王★ 提交于 2019-12-12 09:58:42
问题 Using Sails.js version 0.10.x , assume I have a model Dog , populated as follows (writtenout in yaml format for convenience, but in my case it's actually in a mongo database.) dogs: - breed: "wolf" name: "Fido" - breed: "wolf" name: "Roger" - breed: "dingo" name: "Nipper" - breed: "dingo" name: "Ernie" - breed: "corgi" name: "Bernadi" - breed: "corgi" name: "Queenie" - breed: "poodle" name: "Christopher" - breed: "poodle" name: "Tony" etc So now I want to create a list of the available breeds

How to count occurrences of unique values in Dictionary?

痞子三分冷 提交于 2019-12-12 08:36:03
问题 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? 回答1: 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.

MySQL - select distinct values against a range of columns

大憨熊 提交于 2019-12-12 06:36:28
问题 The following table will store exchange rates between various currencies over time: CREATE TABLE `currency_exchange` ( `id` int(11) NOT NULL AUTO_INCREMENT, `currency_from` int(11) DEFAULT NULL, `currency_to` int(11) DEFAULT NULL, `rate_in` decimal(12,4) DEFAULT NULL, `rate_out` decimal(12,4) DEFAULT NULL, `exchange_date` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci How would I query it to fetch a list the most recent exchange rates?

Count rows on distinct select with multiple columns

人走茶凉 提交于 2019-12-12 06:14:18
问题 I have been searching for some time but not found enough answers to do this myself. I have an MsSQL that looks like this: select count(*) from ( select distinct supplierName, supplierNr from dbo.InvoiceTypeBean ) as a This returns what I want using pure SQL But i need this in hibernate using criteria and/or detachedcriteria: The detached criteria part: DetachedCriteria dCriteria = DetachedCriteria.forClass(clazz); ProjectionList p = Projections.projectionList(); p.add(Projections.property(