MySql【SQL顺序】

SQL顺序

1、 书写顺序

sql 复制代码
select * 
from 表名 
where 条件 
group by 字段 
having 条件 
order by 
limit x,y
------
select cid,sum(score) 
from stu
where sid >= 1002
group by cid
having sum(score) > 100
order by sum(score) desc
limit 1

2、 执行顺序

sql 复制代码
from   获得全部数据10条件
where  过滤一部分数据,剩下9条
group by 分组,4组
having   过滤分组后的数据,剩下3组
select  查询展现数据,这里有聚合的话在此时聚合
order   排序
limit   限制
相关推荐
sim20208 小时前
systemctl isolate graphical.target命令不能随便敲
linux·mysql
档案宝档案管理9 小时前
档案宝自动化档案管理,从采集、整理到归档、利用,一步到位
大数据·数据库·人工智能·档案·档案管理
C_心欲无痕9 小时前
浏览器缓存: IndexDB
前端·数据库·缓存·oracle
lkbhua莱克瓦249 小时前
进阶-索引3-性能分析
开发语言·数据库·笔记·mysql·索引·性能分析
剑来.10 小时前
事务没提交,数据库为什么会越来越慢?
数据库·oracle
IT教程资源C11 小时前
(N-089)基于springboot网上订餐系统
mysql·springboot订餐系统
IT教程资源D11 小时前
[N_083]基于springboot毕业设计管理系统
mysql·springboot毕业设计
韦东东11 小时前
DeepSeek:R1本地RAG 问答: 功能新增,附 六大关键技术优化路径参考
数据库·mysql
Leon-Ning Liu11 小时前
19c RAC 环境 Patch 38326922 应用实战
数据库·oracle
虫小宝11 小时前
优惠券省钱app高并发秒杀系统:基于Redis与消息队列的架构设计
数据库·redis·缓存