select * from student
// 不重复
select distinct sname from student
// 命名
select s.sname 姓名 from student s
select sname from student where sage > 20
// 等价 or
select sname from student where sage in (21,22)
select sname from student where sage >= 21 and sage <= 23
// [] 闭区间
select sname from student where sage between 21 and 23
select sname from student where sage < 21 or sage > 23
select sname from student where sage not between 21 and 23
// 模糊查询
// 姓马的
select sname from student where sname like '马%'
// 马?梅的
select sname from student where sname like '马_梅'
// 不叫马冬梅的
select sname from student where sname not like '马冬梅'
// 'DB_'开头的,定义转移字符
select sage from student where sname like 'DB\_%' escape '\'
// 涉及空值的
select sname from student where address is null
select sname from student where address is not null
// order by, 默认asc
select sname from studnent order by age
// 年龄相同按学号升序排列
select sname from studnent order by age desc, sno asc
select的字段除聚集函数外,必须在group by中出现。而且聚集函数不能作为where子句的条件
left join
b on
连接条件,不用where作为介词子查询基础
不相关子查询
带in谓词的子查询
带ANY(SOME) 或ALL的子查询
小于任意一个即可。
带EXISTS谓词的子查询