惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - 李计刚

怎样定制图表提示? SQL学习笔记之ANSI_NULLS 要生就生双胞胎~ 如何手写代码以生成Composite图表? 在重庆访古~ Infragistics控件在VS.net 2005中使用的注意事项 UltraChart中如何自定义标签? 关于ColumnLine Chart 重庆印象! 用图表向导生成ColumnLineChart 在VS2005中调试JavaScript 那些逝去的美好日子! Infragistics中Custom Layer的实现(翻译) UltraChart绑定数据的问题(翻译) 韩剧已不再风光! 用颜色矩阵实现的图象反转效果 关于:GDI+FAQ的好去处! 我做的数字图象处理 我的Blog开通了!
关于SELECT执行顺序的问题!
李计刚 · 2009-05-19 · via 博客园 - 李计刚

最近准备数据库DBA的面试,碰到考察select语句执行顺序的问题,见附,回头查询了下王珊老师的《数据库系统概论》,里面给SELECT的定义格式为:
SELECT[ALL|DISTINCT]<目标列表达式>[,<目标列表达式>]…
FROM<表名或视图名>[,<表名或视图名>]…
[WHERE<条件表达式>]
[GROUP BY<列名1>][HAVING<条件表达式>]
[ORDER BY<列名2>][ASC|DESC]
文中其对SELECT语句的含义解释为:根据where子句的条件表达式,从FROM子句指定的基本表或视图中找出满足条件的元组,再按Select子句中的目标列表达式,选出元组中的属性值形成结果表。如果有GROUP子句,则将结果按<列名1>的值进行分组,该属性列值相等的元组为一个组。通常会在每组中作用集函数(sum,count,max,min等)。如果GROUP子句带HAVING短语,则只有满足指定条件的组才会输出。如果有ORDER子句,则结果表还要按<列名2>的值的升序或降序排序。
我反复体会了好几遍,感觉这样的叙述很容易让人得出SELECT语句执行顺序为:from,where,目标列表达式,group,使用聚集函数计算,having,order的结论,但是这样的执行顺序总感觉特别扭,与所体会的SELECT的用法不那么匹配,通过网络调研,得到如下结果,特分享出来,希望对大家有所帮助:
1、from子句组装来自不同数据源的数据;
2、where子句基于指定的条件对记录行进行筛选;
3、group by子句将数据划分为多个分组;
4、使用聚集函数进行计算;
5、使用having子句筛选分组;
6、计算所有的表达式;
7、使用order by对结果集进行排序。
有了上述这样的认识,我们来做附录上的两到SQL面试题,答案将很容易,分别是E,C
1)in a select statement that includes a where clause,where is the group by clause placed in the select statement?______。
A. immediately after the select clause
B. before the where clause
C. before the from clause
D. after the order by clause
E. after the where clause
2)in a select statement that includes a where clause,where is the order by clause placed in the select statement?______.
A.immediately after the select clause
B.before the where clause
C.after all clause
D.after the where clause
E.before the from clause