group by与distinct有何区别

如题所述

这两者本质上应该没有可比性,distinct 取出唯一列,group by 是分组,但有时候在优化的时候,在没有聚合函数的时候,他们查出来的结果也一样。

一、group by

英 [ɡru:p bai]   美 [ɡrup baɪ]  

[计][WIN]分组依据

拓展资料

1、This operator also serves as input to the Group By operator.

该操作符还充当Group By操作符的输入。

2、Complete the following steps to create and program the Group By operator. 

完成以下步骤,创建Group By操作符并对它进行配置。

3、With the appropriate access path, the ORDER BY or GROUP BY requirement can be met without sorting. 

使用恰当的访问路径,无需排序即可满足ORDER BY或GROUP BY需求。

4、Drag it to the right of the Group By operator. 

将它拖放到Group By操作符的右边。

二、distinct

英 [dɪˈstɪŋkt]   美 [dɪˈstɪŋkt]  

adj.明显的,清楚的;卓越的,不寻常的;有区别的;确切的

拓展资料

1、I have distinct memories of him in his last years. 

我清楚地记得他最后几年的情况。

2、Another Cup marathon between the two sides is now a distinct possibility. 

双方很可能再进行一场马拉松式的优胜杯比赛。

3、The photograph showed a distinct image. 

照片显出了明晰的影像。

4、I want a distinct answer to my question. 

我要求对我的问题作出明确的答复。

温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2019-08-21

这两者本质上应该没有可比性,distinct 取出唯一列,group by 是分组,但有时候在优化的时候,在没有聚合函数的时候,他们查出来的结果也一样。

一、group by

英 [ɡru:p bai]   美 [ɡrup baɪ]  

[计][WIN]分组依据

拓展资料

1、This operator also serves as input to the Group By operator.

该操作符还充当Group By操作符的输入。

2、Complete the following steps to create and program the Group By operator. 

完成以下步骤,创建Group By操作符并对它进行配置。

3、With the appropriate access path, the ORDER BY or GROUP BY requirement can be met without sorting. 

使用恰当的访问路径,无需排序即可满足ORDER BY或GROUP BY需求。

4、Drag it to the right of the Group By operator. 

将它拖放到Group By操作符的右边。

二、distinct

英 [dɪˈstɪŋkt]   美 [dɪˈstɪŋkt]  

adj.明显的,清楚的;卓越的,不寻常的;有区别的;确切的

拓展资料

1、I have distinct memories of him in his last years. 

我清楚地记得他最后几年的情况。

2、Another Cup marathon between the two sides is now a distinct possibility. 

双方很可能再进行一场马拉松式的优胜杯比赛。

3、The photograph showed a distinct image. 

照片显出了明晰的影像。

4、I want a distinct answer to my question. 

我要求对我的问题作出明确的答复。

本回答被网友采纳
第2个回答  推荐于2017-09-20
他们的功能基本上是不一样的。
distinct消除重复行。
group by是分组语句。
举例来说可能方便一点。
A表id numa 1b 2c 3a 4c 7d 3e 5
如果只选出id列,用distinct和group by 一样的。
select distinct(id) from A;idabcde;select id from A group by id;idabcde;不同之处可能在于group by有排序功能。
但是如果需要加上另一列num,结果不同。
group by 是分组语句,如果用
select id,num from A group by id,num;
这样的结果在本例中与不加group by是一样的,因为num各个不同。
但是如果select id,num from A group by id;
注意该语句是错误语句,因为num没有使用聚组函数,例如:sum(求和),avg(求平均数)
select id,sum(num) from A group by id;
id sum(num)a 5b 2c 10d 3e 5
用distinct不显示重复的行。
在本例中select distinct id,num from A;的结果也和不加distinct一致。
因为id,num没有重复的行,而不是只看id。
group by 功能更强大一些,另外推荐使用group by。
因为distinct会导致全表扫描,而group by如果索引建的
恰当的话,会有性能上的提高。本回答被提问者采纳
第3个回答  推荐于2019-08-22

group by与distinct的区别:

1、distinct英式发音为[dɪˈstɪŋkt,美式发音为[dɪˈstɪŋkt] ,意思有:明显的,清楚的;卓越的,不寻常的;有区别的;确切的。

2、group by意思有:根据(by)一定的规则进行分组(Group)”。它的作用是通过一定的规则将一个数据集划分成若干个小的区域,然后针对若干个小区域进行数据处理。

拓展资料

group by

1、It can improve performance if columns involved in ORDER BY and GROUP BY are indexed.

如果为ORDER BY和GROUP BY所涉及的列建立了索引,那么可以提高性能。

2、The attributes appear in both the SELECT clause and the GROUP BY clause. 

这些属性出现在SELECT子句和GROUP BY子句中。

3、Any such groupings are listed in the GROUP_BY attribute of the root element. 

所有这样的分组都在根元素的GROUP BY属性中列出。

4、This operator also serves as input to the Group By operator. 

该操作符还充当Group By操作符的输入。

5、Complete the following steps to create and program the Group By operator. 

完成以下步骤,创建Group By操作符并对它进行配置。

6、With the appropriate access path, the ORDER BY or GROUP BY requirement can be met without sorting. 

使用恰当的访问路径,无需排序即可满足ORDER BY或GROUP BY需求。

distinct

1、Engineering and technology are disciplines distinct from one another and from science

工程学和工艺学互不相同,也有别于自然学科。

2、Now that Tony was no longer present, there was a distinct change in her attitude 

由于托尼不在场了,她的态度有了明显的转变。

3、Being 6ft 3in tall has some distinct disadvantages! 

身高6英尺3英寸有些明显的不便之处!

4、There's a lot of evidence that oily fish, as distinct from fatty meat, has a beneficial effect.

有许多证据表明油性鱼,与高脂肪肉不同,对人体有益。

5、This book is divided into two distinct parts. 

这本书分为内容不同的两部分。

本回答被网友采纳
相似回答