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   限制
相关推荐
shirsl2 小时前
数据开发实时项目问题整理
数据库·sql·big data
bbq粉刷匠2 小时前
数据库设计实践
数据库
java_logo2 小时前
Docker 部署 ClickHouse Server:轻松搭建列式 OLAP 分析数据库平台
数据库·clickhouse·docker·私有化部署·olap·列式数据库·轩辕镜像
盛世宏博智慧档案2 小时前
高速 ETC 门架外场机房温湿度远程监测解决方案
服务器·数据库·php·高度·高速·温湿度
—Miss. Z—2 小时前
计算机三级数据库技术—应用题2️⃣
数据库·mysql
PrudentWoo2 小时前
PostgreSQL 12 登录失败:role “postgres“ is not permitted to log in 的排查与修复
数据库·postgresql
这个DBA有点耶3 小时前
临时表从4.7秒到0.12秒:不是所有Using temporary都需要优化
数据库·mysql·代码规范
天衍四九-3 小时前
排查慢SQL用explain分析执行计划,主要关注哪些字段?
数据库·sql
Meta393 小时前
PostgreSQL报SELECT rule‘s target entry X has different type from column “XXX“
数据库·postgresql·dubbo
洋不写bug3 小时前
二叉树(四)经典算法题目解析,公共祖先,二叉树构造,非递归遍历
数据库·算法·二叉树·二叉树构造·公共祖先