当前位置:网站首页>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
边栏推荐
- XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
- 【zeno】为zeno增加子模块/新节点的最小化的例子
- 为什么sys_class 里显示的很多表的 RELTABLESPACE 值为 0 ?
- dotnet OpenXML 解析 PPT 图表 面积图入门
- 科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
- EU | Horizon 2020 ENSEMBLE: D2.13 SOTIF Safety Concept (Part 2)
- 我的杂记链接
- 施一公:科学需要想象,想象来自阅读
- 无题三
- Example of Noise Calculation for Amplifier OPA855
猜你喜欢

营销建议 | 您有一份八月营销月历待查收! 建议收藏 !

开源一夏|OpenHarmony如何查询设备类型(eTS)

Creo 9.0 基准特征:基准坐标系

sql server中 两表查询 平均数 分组

Dry goods!Generative Model Evaluation and Diagnosis

并发之CAS

微服务 技术栈

只有一台交换机,如何实现主从自动切换之nqa

js graphics operation one (compatible with pc, mobile terminal to achieve draggable attribute drag and drop effect)

19.服务器端会话技术Session
随机推荐
营销建议 | 您有一份八月营销月历待查收! 建议收藏 !
PAT乙级-B1019 数字黑洞(20)
19.服务器端会话技术Session
C语言的高级用法
韦东山 数码相框 项目学习(六)tslib的移植
为什么我推荐使用智能化async?
MQTT X Newsletter 2022-07 | 自动更新、MQTT X CLI 支持 MQTT 5.0、新增 conn 命令…
express hot-reload
无题十二
Oracle temporary table space role
无题二
程序员的七种武器
Why do I recommend using smart async?
Xcode 12 ld: symbol(s) not found for architecture armv64
IDEA执行Test操作导致数据插入时出现了重复数据
仿SBUS与串口数据固定转换
pytorch余弦退火学习率CosineAnnealingLR的使用
C语言-数组
There is only one switch, how to realize the nqa of master-slave automatic switching
长达四年的减肥记录