ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

7.3.3. DISTINCT

2021-01-01 22:00:48  阅读:251  来源: 互联网

标签:rows DISTINCT 7.3 considered expression SELECT


7.3.3. DISTINCT

7.3.3. DISTINCT

After the select list has been processed, the result table can optionally be subject to the elimination of duplicate rows. The DISTINCT key word is written directly after SELECT to specify this:

选择列表执行完后,也可以选择将结果集去重。SELECT后直接指定DISTINCT关键词可以实现该需求:

 

SELECT DISTINCT select_list ...

(Instead of DISTINCT the key word ALL can be used to specify the default behavior of retaining all rows.)

(可以使用关键字ALL来指定默认行为:保留所有行。)

 

Obviously, two rows are considered distinct if they differ in at least one column value. Null values are considered equal in this comparison.

很明显,如果两行至少有一个列值不同,则被认为是不同的。此比较中,空值视为相等。

 

Alternatively, an arbitrary expression can determine what rows are to be considered distinct:

可选的,可以使用一个表达式来决定distinct针对哪些行:

 

SELECT DISTINCT ON (expression [, expression ...]) select_list ...

Here expression is an arbitrary value expression that is evaluated for all rows. A set of rows for which all the expressions are equal are considered duplicates, and only the first row of the set is kept in the output. Note that the “first row” of a set is unpredictable unless the query is sorted on enough columns to guarantee a unique ordering of the rows arriving at the DISTINCT filter. (DISTINCT ON processing occurs after ORDER BY sorting.)

这里的expression是一个针对所有行求值的任意值表达式。一组所有表达式均相等的行被视为重复行,并且仅该行集的第一行保留在输出中。请注意,除非查询在足够的列上排序以保证到达DISTINCT过滤器的行的唯一顺序,否则集合的“第一行”是不可预测的。(DISTINCT ON在ORDER BY排序之后进行处理。)

 

The DISTINCT ON clause is not part of the SQL standard and is sometimes considered bad style because of the potentially indeterminate nature of its results. With judicious use of GROUP BY and subqueries in FROM, this construct can be avoided, but it is often the most convenient alternative.

DISTINCT ON子句并不是SQL标准的一部分,由于其结果可能不确定,因此有时被认为是不良语法。 通过明智地使用GROUP BY和FROM中的子查询,可以避免这种语法,但是它通常是最方便的选择。

标签:rows,DISTINCT,7.3,considered,expression,SELECT
来源: https://blog.csdn.net/ghostliming/article/details/112072225

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有