当前位置:网站首页>Can MySQL use aggregate functions without GROUP BY?
Can MySQL use aggregate functions without GROUP BY?
2022-08-05 09:32:00 【CSDN q&a】
I am a new data product, and I wrote a query today for a store that has not generated orders in the last 15 days.The SQL written by Data Development is 8 times faster than the results I wrote.
There is one place that I really don't understand, please ask for help humbly.
Written by me
SELECT s.id FROM `store`s JOIN ( SELECT `store_id` , MAX( `create_time`)t FROM `order` GROUP BY `store_id` )aON s.id = a.store_idWHERE s.channel = 2 ANDs.show = 1 AND DATEDIFF(now(), a.t ) > 15 Written by Data Development
SELECT idFROM `store`s where s.channel = 2 AND s.show = 1 AND DATEDIFF(now(), (SELECT MAX( `create_time`) FROM `order` o where o.store_id = s.id)) > 15 After reading the performance analysis of my SQL, it is because there are too many rows of order table data (about tens of millions), and the GROPU BY grouping is used to cause performance.
The development and writing avoided the use of GROPU BY, but my skills are relatively shallow, so I can't understand it:
In AND DATEDIFF(now(), (SELECT MAX(`create_time`) FROM `order` o where o.store_id = s.id)) > 15 In this query condition, the subquery statement outputs MAX time, but if group aggregation is not used, the output is notShould there be only one row of data?Why can I achieve my requirement of grouping by store_id?Although I probably guessed that the core lies in the following o.store_id = s.id, but I didn't understand it
边栏推荐
- Creo 9.0 基准特征:基准轴
- 无题十三
- How ali cloud storage database automatically to speed up the loading speed of www.cxsdkt.cn how to set up the case?
- dotnet OpenXML 解析 PPT 图表 面积图入门
- Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
- PAT Level B - B1021 Single Digit Statistics (15)
- 【LeetCode】623. Add a row to the binary tree
- There is only one switch, how to realize the nqa of master-slave automatic switching
- 2022.8.3
- Undefined symbols for architecture arm64解决方案
猜你喜欢

Weekly Report 2022-8-4

dotnet OpenXML 解析 PPT 图表 面积图入门

哪位大佬有20年4月或者1月的11G GI和ojvm补丁呀,帮忙发下?

CCVR基于分类器校准缓解异构联邦学习

Assembly language (8) x86 inline assembly

如何实现按键的短按、长按检测?

CCVR eases heterogeneous federated learning based on classifier calibration

eKuiper Newsletter 2022-07|v1.6.0:Flow 编排 + 更好用的 SQL,轻松表达业务逻辑

egg框架使用(一)

Creo 9.0 基准特征:基准平面
随机推荐
Two-table query average grouping in sql server
C语言的高级用法
Creo 9.0 基准特征:基准坐标系
PAT乙级-B1021 个位数统计(15)
无题三
Example of Noise Calculation for Amplifier OPA855
Overall design and implementation of Kubernetes-based microservice project
tensorflow.keras cannot introduce layers
leetcode refers to Offer 10- II. Frog jumping steps
请问大佬们 ,使用 Flink SQL CDC 是不是做不到两个数据库的实时同步啊
无题四
2.4G无线收发模块的应用
express hot-reload
openpyxl to manipulate Excel files
sql server中 两表查询 平均数 分组
蚁剑webshell动态加密连接分析与实践
Advanced usage of C language
leetcode 剑指 Offer 10- II. 青蛙跳台阶问题
正则表达式replaceFirst()方法具有什么功能呢?
开源一夏|OpenHarmony如何查询设备类型(eTS)