SQL Server中Group By、Having和Where子句的执行顺序? [英] Execution sequence of Group By, Having and Where clause in SQL Server?

查看:40
本文介绍了SQL Server中Group By、Having和Where子句的执行顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们使用带有 WHERE 子句的 GROUP BYHAVING 时,我只是对 SQL 查询的执行顺序感到困惑.哪个先执行?顺序是什么?

I am just confused with the execution sequence of a SQL query when we use GROUP BY and HAVING with a WHERE clause. Which one gets executed first? What is the sequence?

推荐答案

按顺序:

来自 &JOINs 决定 &过滤行
WHERE 行上的更多过滤器
GROUP BY 将这些行组合成组
HAVING 过滤器组
ORDER BY 排列剩余的行/组
LIMIT 过滤剩余的行/组

FROM & JOINs determine & filter rows
WHERE more filters on the rows
GROUP BY combines those rows into groups
HAVING filters groups
ORDER BY arranges the remaining rows/groups
LIMIT filters on the remaining rows/groups

这篇关于SQL Server中Group By、Having和Where子句的执行顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆