查询
语法格式:
select [all | distinct] <目标表达式>
form <表名或试图名>
where <条件表达式>
group by <列名 1> having <条件表达式>
order by <列名 2> [asc | desc];
如果有group by ,则结果按 列名1的值进行分组,该属性列值相等的元组为一个组,通常会在每组中作业聚集函数
如果group by 字句带having 短句,则只有满足指定条件的组才予以输出
如果有order by 则结果集还要按列名2的值的升序或降序排序
用户可以指定别名来改变查询结果的列标题
如 select sname NAME ,‘Year of Birth’ BIRTH,2019-Sage BIRTHDAY,
LOWER(Sdept)DEPATMENT
FROM Student
select distinct sno
distinct 去掉结果表中的重复行
select all sno
all 保留结果的重复行
常用的查询条件
比较:= , > , < , >= , <= , != , <> , !> , !< ;
确定范围 between and,not between and
确定集合 in , not in
字符匹配 like , not like
空值 is null , is not null
多重条件 and , or , not