当前位置:网站首页>SQL中只要用到聚合函数就一定要用到group by 吗?
SQL中只要用到聚合函数就一定要用到group by 吗?
2022-06-25 22:18:00 【Archie_java】
SQL中只要用到聚合函数就一定要用到group by 吗?
今天记录一个弱智问题,一直没发现这个问题。
答:看情况
1、当聚集函数和非聚集函数出现在一起时,需要将非聚集函数进行group by
2、当只做聚集函数查询时候,就不需要进行分组了。
举例来说,
SELECT SUM(TABLE.A ) FROM TABLE
上述SQL不需要使用Group by 进行分组,因为其中没有非聚合字段,所以不用Group by 也可以。
如果是SELECT SUM(TABLE.A ),MAX(B), FROM TABLE GROUP BY B
由于B是非聚合字段,则需要使用MAX()或者其他聚合函数并且Group by 才可以正常执行。
边栏推荐
- Thrift getting started
- 10.4.1 data console
- Introduction to anchor free decision
- The problem of low video memory in yolov5 accelerated multi GPU training
- Explain in detail the three types of local variables, global variables and static variables
- redux工作流程讲解+小例子
- Mysql5.7.31自定义安装详细说明
- Shredding Company poj 1416
- 解决线程并发安全问题
- Bit compressor [Blue Bridge Cup training]
猜你喜欢
Search rotation array ii[Abstract dichotomy exercise]
About Simple Data Visualization
MySQL master-slave replication
Common problems encountered when creating and publishing packages using NPM
Explain in detail the three types of local variables, global variables and static variables
EBS r12.2.0 to r12.2.6
What is micro service
每日刷题记录 (四)
Thrift getting started
10.4.1、数据中台
随机推荐
How to configure SQL Server 2008 Manager_ Old bear passing by_ Sina blog
Thrift入门学习
Keil compilation run error, missing error: # 5: # includecore_ cm3.h_ Old bear passing by_ Sina blog
Rocket message storage
Shredding Company poj 1416
huibian
Prototype chain test questions in JS --foo and getname
redux工作流程讲解+小例子
Object array de duplication
dhcp复习
Bit compressor [Blue Bridge Cup training]
10.2.3、Kylin_ The dimension is required for kylin
EBS R12.2.0升级到R12.2.6
The problem of low video memory in yolov5 accelerated multi GPU training
Some basic uses of mongodb
10.3.1、FineBI_ Installation of finebi
Servlet response download file
About Simple Data Visualization
EBS r12.2.0 to r12.2.6
SSL unresponsive in postman test