Heim  >  Artikel  >  Datenbank  >  数据库操作--查询(续)

数据库操作--查询(续)

WBOY
WBOYOriginal
2016-06-07 16:10:291214Durchsuche

1、常用的查询条件: (1)比较 =,,,=,=,!=(不等于),(不等于),!(不大于),!;not上述比较运算符 (2)确定范围 between and , not between and (3)确定集合 in , not in (4)字符匹配 like , not like (5)空 is null , is not null (6)多重条件(

1、常用的查询条件:
(1)比较 =,>,=,(不等于),!>(不大于),! (2)确定范围 between and , not between and
(3)确定集合 in , not in
(4)字符匹配 like , not like
(5)空值 is null , is not null
(6)多重条件(逻辑运算)and , or , not
2、聚集函数
count([distinct | all] * ) /*统计元组个数*/
count([distinct | all] ) /*统计一列中值的个数*/
sum([distinct | all] ) /*计算一列值的总和(此列必须是数值型)*/
avg([distinct | all] ) /*计算一列值得平均值(此列必须是数值型)*/
Max([distinct | all] ) /*求一列中的最大值*/
min([distinct | all] ) /*求一列中的最小值*/
如果指定distinct短语,则表示在计算时要取消指定列中的重复值
如果指定all短语,则表示不取消重复值。all为缺省值
3、连接查询

(1)等值与非等值连接查询

格式为:[.][.]
其中 比较运算符主要有:=、>、=、)等
此外链接谓词还可以使用下面形式:
[.][.] and [.]
当链接运算符为=时,称为等值连接,使用其他运算符称为非等值连接
(2)自身连接
(3)外连接:把舍弃的元组也保存在结果关系中,而在其他属性上填空值(null),那么这种连接叫做外连接
(4)复合条件连接:where子句中有多个连接条件,称为符合连接
连接操作除了可以使两表连接,一个表与其自身连接外,还可以是两个以上的表进行连接,后者通常称为多表连接。
4、嵌套查询:一个子查询还可以嵌套其他子查询
注意:子查询的select 语句中不能使用order by 子句,group by 子句不能对最终查询结果排序
(1)带有IN谓词的子查询
(2)带有运算符的子查询
(3)带有any(some)或all的子查询
(4)带有exists的子查询

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:XPath快速解析XMLNächster Artikel:如何利用ash监控会话