Maison > base de données > tutoriel mysql > le corps du texte

SQL学习(持续更新)

WBOY
Libérer: 2016-06-07 17:42:37
original
912 Les gens l'ont consulté

1、having筛选分组 正如where子名限制了select显示的行数,having限制了group by显示的分组数。where查询条件在分组产生前就被计算,而having搜索条件在分组产生之后才被应用。除了having子句可以包含聚合函数以外,having语法类似于where语法。having子句可

1、having筛选分组

      正如where子名限制了select显示的行数,having限制了group by显示的分组数。where查询条件在分组产生前就被计算,服务器空间,香港服务器租用,而having搜索条件在分组产生之后才被应用。除了having子句可以包含聚合函数以外,having语法类似于where语法。having子句可以引用显示在select列表中的任何一项。

      总结:(1)where子句从from和join子句指定的运算结果中筛选行;(2)group by子句对where子句的输出进行分组;(3)having子句对分组后的结果筛选行。 

2、DBMS处理联结时,按照以下顺序执行整个查询 

(1)在join子句中应用联结条件。 

(2)在where子句中应用联结条件和查询条件。 

(3)按照group by子句对行分组。 

(4)在having子句中对分组应用搜索条件。  

(5)按照order by子句对结果排序。    

3、using子句 

      对于join语法,如果被联结的列有相同的名字且被用于比较是否相等,SQL标准定义了替代on子句的using子句。 

例如: 

select [name],[city] from [authors] inner join [publishers] using([city]);

4、使用all比较所有子查询的值 

      在子查询比较中,all修改了比较操作符,并且跟在=、、、>=之后, 表示等于、不等于、大于、小于子查询的结果中的所有值。

例如: 

select * from [table1] where [col1]>all (select [col1] from [table2]); 

5、使用any比较子查询的值 

      确定是否一个值等于、大于、小于子查询的结果中的某个值。 

6、使用exists检测存在性

       exists和not exists不比较值,而是在子查询结果中确定存在或不存在行。

例如: 

select [pub_name] from [publishers] p where exists (select * from [titles] t where t.[pub_id]=p.[pub_id] and [type]='biography'); 

7、集合操作 

(1)union返回两个查询返回的所有行,香港服务器,但会删除重复行。 

select_statement1 union [all]  select_statement2;

(2)intersect返回两个查询返回的所有共同行。

select_statement1 intersect select_statement2; 

(3)except返回第一个查询存在,但第二个查询中不存在的所有行,删除重复行。 

select_statement1 except select_statement2; 

 

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!