Any reason for GROUP BY clause without aggregation function?(没有聚合功能的 GROUP BY 子句的任何原因?)
问题描述
我正在(彻底)学习 SQL 并且遇到了 GROUP BY 子句.
I'm (thoroughly) learning SQL at the moment and came across the GROUP BYclause.
GROUP BY 根据您提供的参数对结果集进行聚合或分组.如果在查询中使用此子句,则可以对结果集执行聚合函数以查找结果集的统计信息,例如查找平均值 (AVG()) 或频率 (COUNT())代码>.
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()).
我的问题是:没有附带聚合函数的 GROUP BY 语句是否有用?
My question is: is the GROUP BY statement in any way useful without an accompanying aggregate function?
更新使用 GROUP BY 作为 DISTINCT 的同义词是(可能)一个坏主意,因为我怀疑它更慢.
Update
Using GROUP BY as a synonym for DISTINCT is (probably) a bad idea because I suspect it is slower.
推荐答案
GROUP BY 语句在没有附带聚合函数的情况下是否有用?
is the GROUP BY statement in any way useful without an accompanying aggregate function?
在这种情况下使用 DISTINCT 将是同义词,但您想要/必须定义 GROUP BY 子句的原因是为了能够定义HAVING 子句细节.
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.
如果你需要定义一个 HAVING 子句,你必须定义一个 GROUP BY - 你可以不要与 DISTINCT 结合使用.
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 子句的任何原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:没有聚合功能的 GROUP BY 子句的任何原因?
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
