数据库 DQL 数据库查询语句

符号约定:
    <> 必须
    [] 可选
    {}或|:必须选其中之一
    [,...N]:前面的项可以重复多次

select [all|distinct] <目标表达式>     --distinct去掉重复行
from <表名或视图名> 
where <条件表达式>
group by <列名1> [having <条件表达式>]
order by <列名2> [asc|desc];

select 字段 [as] <别名> from 表名 where 条件表达式

1.单表查询

select Sno from SC; -- 查询所有行的学号   等价于select all Sno from SC;
select distinct Sno from SC; -- 查询所有行学号 去掉重复行 (相当于查询共有多少种学号)

2.查询条件

常用查询条件
查询条件 谓词
比较 =,>,<,>=,<=,!=,<>,!>,!<;not 加上述比较运算符
确定范围 between and , not between and
确定集合 in , not in
字符匹配 like , not like
空值 is null , is not null
多重条件(逻辑运算) and , or , not

!=与<>都是不等于

2.1 比较

select Sname from Student where sdept='CS';
select Sname,Sage from Student where Sage<20;
select distinct Sno from SC where Grade<60;

2.2范围

猜你喜欢

转载自blog.csdn.net/hza419763578/article/details/83267936