GROUP BY 如何工作?

How does GROUP BY work?(GROUP BY 如何工作?)
本文介绍了GROUP BY 如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个带有属性的表 Tab1 - a1a2 等等.没有一个属性是唯一的.

Suppose I have a table Tab1 with attributes - a1, a2, ... etc. None of the attributes are unique.

以下查询的性质是什么?它会始终返回一行吗?

What will be the nature of the following query? Will it return a single row always?

SELECT a1, a2, sum(a3) FROM Tab1 GROUP BY a1, a2

推荐答案

GROUP BYGROUP BY 字段的每个唯一组合返回一行.因此,在您的示例中, (a1, a2) 出现在 Tab1 行中的每个不同组合都会导致查询中的一行代表具有给定组合的行组按字段值分组.SUM() 等聚合函数是针对每个组的成员计算的.

GROUP BY returns a single row for each unique combination of the GROUP BY fields. So in your example, every distinct combination of (a1, a2) occurring in rows of Tab1 results in a row in the query representing the group of rows with the given combination of group by field values . Aggregate functions like SUM() are computed over the members of each group.

这篇关于GROUP BY 如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)