distinct

How do I get distinct characters of string column in mssql?

∥☆過路亽.° 提交于 2019-12-10 16:16:12
问题 Given: | name -+--------------------------- | Josef Knoller | Josef Somos | KFZ Wiesauer wanted result: JOSEFKNMLRZWIAU (case in the result does not matter - it was just easier holding the UPPER key while writing) Is there any way to do this in T-SQL ? sorry ... i've mixed column and row ... it's 1 column and n rows MLRZWIAU M comes from Somos L comes from Knoller R comes from Knoller ... clearer? 回答1: DECLARE @result VARCHAR(MAX) SET @result = '' DECLARE @t TABLE(name VARCHAR(400)) INSERT

SELECT DISTINCT still showing duplicates

怎甘沉沦 提交于 2019-12-10 15:16:03
问题 Yes, there's a thousand questions about this on SO, but I've been searching for half an hour and I've yet to find a solution. So, I've a table like this: And this is my query: SELECT DISTINCT rengasID,leveys FROM renkaat ORDER BY leveys ASC And this is the result I get: If you get the idea, I'm populating a select field with it, but it still has duplicates. What am I doing wrong? 回答1: If you want distinct levey s, just choose that field: SELECT DISTINCT leveys FROM renkaat ORDER BY leveys ASC

No duplicates in SQL query

↘锁芯ラ 提交于 2019-12-10 13:52:28
问题 I'm doing a select in MySQL with an inner join: SELECT DISTINCT tblcaritem.caritemid, tblcar.icarid FROM tblcaritem INNER JOIN tblprivatecar ON tblcaritem.partid = tblprivatecar.partid INNER JOIN tblcar ON tblcaritem.carid = tblcar.carid WHERE tblcaritem.userid=72; Sometimes I get duplicates of tblcaritem.caritemid in the result. I want to make sure to never get duplicates of tblcaritem.caritemid, but how can I do that? I tried to use DISTINCT but it just checked if the whole row is a

Oracle - With a one to many relationship, select distinct rows based on a min value

孤街醉人 提交于 2019-12-10 12:12:58
问题 This question is the same as In one to many relationship, return distinct rows based on MIN value with the exception that I'd like to see what the answer looks like in other dialects, particularly in Oracle. Reposting from the original description: Let's say a patient makes many visits. I want to write a query that returns distinct patient rows based on their earliest visit. For example, consider the following rows. patients ------------- id name 1 Bob 2 Jim 3 Mary visits ------------- id

Get distinct values from each table and each column with SQL Server

别说谁变了你拦得住时间么 提交于 2019-12-10 12:06:36
问题 I would like to loop through each table for a given database to get unique values for each char field. My query might something like: for each table: for each row in table: select distinct char_field from table loop loop How do I do this? 回答1: Try it like this DECLARE cur CURSOR FOR SELECT 'SELECT DISTINCT ' + QUOTENAME(c.COLUMN_NAME) + 'AS ' + QUOTENAME(TABLE_CATALOG + '.' + TABLE_SCHEMA + '.' + TABLE_NAME) + ' FROM ' + QUOTENAME(TABLE_CATALOG) + '.' + QUOTENAME(TABLE_SCHEMA) + '.' +

ProgrammingError: when using order_by and distinct together in django

旧时模样 提交于 2019-12-10 11:09:55
问题 I have a model like below class ProductScore(models.Model): client = models.ForeignKey(User) created = models.DateTimeField(default=datetime.datetime.now) score = models.IntegerField() scale = models.ForeignKey(Product) As of now i am using the below query to filter out the duplicates from the above model scores = ProductScore.objects.filter(client=request.user).distinct('scale') By the above query it was returning the unique results but are old(created date was very old), i mean for example

SQL聚合函数

ぃ、小莉子 提交于 2019-12-10 03:24:29
聚合函数对一组值计算后返回单个值。除了count(统计项数)函数以外,其他的聚合函数在计算式都会忽略空值(null)。所有的聚合函数均为确定性函数。即任何时候使用一组相同的输入值调用聚合函数执行后的返回值都是相同的,无二义性。T-SQL提供的聚合函数一共有13个之多。   聚合函数通常会在下列场合使用:    1、select语句的选择列表,包括子查询和外部查询。    2、使用compute或compute by产生汇总列时。    3、having子句对分组的数据记录进行条件筛选。 聚合函数    1、平均值AVG  AVG函数用于计算精确型或近似型数据类型的平均值,bit类型除外,忽略null值。AVG函数计算时将计算一组数的总和,然后除以为null的个数,得到平均值。  语法结构:   avg( [ all | distinct ] expression )    all:为默认值,表示对所用的数据都计算平均值。  distinct:每个值的唯一值计算平均值,不管相同的值出现多次,多个行相同的值仅仅出现一次作为计算。  expression:精确或近似值的表达式。表达式内部不允许使用子查询和其他聚合函数。  示例:   select avg(distinct age) from person -- 查询person表里的年龄的平均值,相同值只计算一次    2、最小值MIN

LINQ - writing a query with distinct and orderby

时光总嘲笑我的痴心妄想 提交于 2019-12-10 02:06:32
问题 I'm quite new to LINQ. Suppose that I had the following table: Incident ID DeviceID Time Info 1 1 5/2/2009 d 2 2 5/3/2009 c 3 2 5/4/2009 b 4 1 5/5/2009 a In LINQ, how could I write a query that finds the most recent and distinct (on Device ID) set of incidents? The result I'd like is this: ID DeviceID Time Info 3 2 5/4/2009 b 4 1 5/5/2009 a Do you have to create an IEqualityComparer to do this? 回答1: You can get the most recent incidents for each device (this is how I understood your question)

rails COUNT SELECT DISTINCT

十年热恋 提交于 2019-12-10 01:28:57
问题 I'm recording the number of times users watch a series of videos. Now I'm trying to make a graph of the number of users who watch any video each day. UserVideoWatching.where("created_at >= ? AND user_id != ?",1.month.ago, User.elephant.id).group("DATE(created_at)").reorder('created_at').count produces the sql SELECT COUNT(*) AS count_all, DATE(created_at) AS date_created_at FROM `user_video_watchings` WHERE (created_at >= '2013-01-27 10:43:24' AND user_id != 7) GROUP BY DATE(created_at) ORDER

Distinct on specific column in Hive

醉酒当歌 提交于 2019-12-10 01:23:23
问题 I am running Hive 071 I have a table, with mulitple rows, with the same column value e.g. x | y | --------- 1 | 2 | 1 | 3 | 1 | 4 | 2 | 2 | 3 | 2 | 3 | 1 | I want to have the x column unique, and remove rows that have the same x val e.g. x | y | --------- 1 | 2 | 2 | 2 | 3 | 2 | or x | y | --------- 1 | 4 | 2 | 2 | 3 | 1 | are both good as distinct works only on the whole rs in hive, I couldn't find a way to do it help please Tx 回答1: You can use the distinct keyword: SELECT DISTINCT x FROM