当前位置:网站首页>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 才可以正常执行。
边栏推荐
- Daily question brushing record (IV)
- MySQL master-slave replication
- oracle RAC 集群无法启动
- SMT贴片加工PCBA板清洗注意事项
- Setting up a cluster environment under Linux (2) -- installing MySQL under Linux
- Literature research (III): overview of data-driven building energy consumption prediction models
- 11.1.1、flink概述_flink概述
- My blog is 2 years old and 167 days old today. I received the pioneer blogger Badge_ Old bear passing by_ Sina blog
- tensorrt pb转uff问题
- Redis memory elimination mechanism
猜你喜欢

mysql 主从复制

Reading notes on how to connect the network - hubs, routers and routers (III)

文献调研(四):基于case-based reasoning、ANN、PCA的建筑小时用电量预测

MySQL master-slave replication

anchor free dection简介
![[advanced ROS] Lecture 1 Introduction to common APIs](/img/25/85e8c55605f5cc999a8e85f0a05f93.jpg)
[advanced ROS] Lecture 1 Introduction to common APIs

Common problems encountered when creating and publishing packages using NPM

Thrift入门学习

Redis jump table

快手实时数仓保障体系研发实践
随机推荐
Redis memory elimination mechanism
SMT操作员是做什么的?工作职责?
Redis之内存淘汰机制
Redis jump table
STEP7 master station and remote i/o networking_ Old bear passing by_ Sina blog
SPI锡膏检查机的作用及原理
Building cloud computers with FRP
My blog is 2 years old and 167 days old today. I received the pioneer blogger Badge_ Old bear passing by_ Sina blog
oracle RAC 集群无法启动
Reading notes on how to connect the network - hubs, routers and routers (III)
Efficacy of kiwi fruit enzyme_ Old bear passing by_ Sina blog
logstash丢弃没有精准匹配到文件名的日志数据
Ora-01153: incompatible media recovery activated
快手实时数仓保障体系研发实践
Smt贴片机保养与维护要点
Idea common shortcut keys
Installing redis on Linux
SMT葡萄球现象解决办法
Sentinel of redis
DBCA silent installation and database building