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   限制
相关推荐
CoderYanger4 小时前
Java EE 进阶:9.MyBatis 操作数据库(进阶)(第八弹):MyBatis Generator
java·数据库·spring boot·spring·java-ee·tomcat·mybatis
MSTcheng.5 小时前
【MySQL】MySQL数据库——表的操作
数据库·mysql·adb
FungLeo5 小时前
FengCMS · PHP+MySQL 升级实录 · 内容写入一致性:锁等待超时与跨模型子树删除竞态
开发语言·mysql·php·工程实践·fengcms
Yeats_Liao6 小时前
物联网平台MongoDB实战|(一)为什么选择MongoDB
数据库·物联网·mongodb
ZhengEnCi6 小时前
覆盖索引是什么:用借书和外卖看懂回表这件事
sql·mysql·postgresql
鹤落晴春6 小时前
MySQL日志梳理
运维·数据库·mysql
五彩小白7 小时前
Redis的过期删除和内存淘汰机制
数据库·redis·缓存
学长毕设8 小时前
基于SpringBoot 博物馆文物租赁及修复管理系统-附源码
大数据·数据库·spring boot
FungLeo8 小时前
FengCMS · PHP+MySQL 升级实录 · MySQL DDL不能回滚:模型字段结构操作的失败续做
android·mysql·php·工程实践·fengcms
apcipot_rain8 小时前
C++转Java日记(14)
数据库