没有聚合函数的GROUP BY子句的任何原因? [英] Any reason for GROUP BY clause without aggregation function?
问题描述
我现在(彻底)在学习SQL,并遇到了 GROUP BY
子句。
GROUP BY
根据您提供的参数对结果集进行聚合或分组。如果在查询中使用此子句,则可以对结果集执行集合函数以查找有关结果集的统计信息,如查找平均值(AVG())
或频率。
我的问题是:GROUP BY语句在没有附加聚合函数的情况下是否有用?
更新
使用 GROUP BY
作为<$ c的同义词$ c> DISTINCT 是(可能)不好的主意,因为我怀疑它比较慢。
是GROUP BY语句,在任何情况下都没有附带的集合函数吗?
使用 DISTINCT
在这种情况下会是一个同义词,但是您希望/必须定义 GROUP BY
子句的原因是为了能够定义 HAVING
子句的详细信息。
如果您需要定义 HAVING
子句,哟 来定义 GROUP BY
- 您不能与 DISTINCT
。
I'm (thoroughly) learning SQL at the moment and came across the GROUP BY
clause.
GROUP BY
aggregates or groups the resultset according to the argument(s) you give it. If you use this clause in a query you can then perform aggregate functions on the resultset to find statistical information on the resultset like finding averages (AVG())
or frequency (COUNT())
.
My question is: is the GROUP BY statement in any way useful without an accompanying aggregate function?
Update
Using GROUP BY
as a synonym for DISTINCT
is (probably) a bad idea because I suspect it is slower.
is the GROUP BY statement in any way useful without an accompanying aggregate function?
Using DISTINCT
would be a synonym in such a situation, but the reason you'd want/have to define a GROUP BY
clause would be in order to be able to define HAVING
clause details.
If you need to define a HAVING
clause, you have to define a GROUP BY
- you can't do it in conjunction with DISTINCT
.
这篇关于没有聚合函数的GROUP BY子句的任何原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!