数据库学习(2.2条件查询)DQL语句

二,条件查询
#基本语法
select 查询列表 from 表名 where 筛选条件;

#分类
1,按条件表达式筛选
条件运算符:< ,>,=,!=(<>),>=,<=

2,按逻辑表达式筛选
逻辑运算符:
&& || !(and or not)
and:只要一个为false,则为false;
or:一个为true,则为true.

3,模糊查询
like,between and,in,is,null
*like关键字的讲解:lile通常与通配符搭配使用(通配符:任意多个字符,包含0个字符;任意单个字符);
1)查询含有a的字段
where 字段 like(’%a%’);
2)查询第三个字符为e,第五个字符为a的字段;
where 字段 like ‘__e_a%’.
3)查询第二个字符为_的字段(转义)
a.where 字段 like '
_%’;
b.where 字段 like '_KaTeX parse error: Expected group after '_' at position 1: _̲%' escape 's';(…为转义)
*between and模糊查询.语法;where 字段 between 100 and 120;
1)使用between and可以提高语句简洁度
2)包含临界值
3)两个临界值不能颠倒顺序
*in关键字模糊查询:判断某字段的值是否属于in列表中的某一项
特点:
1)使用in提高语句简洁度
2)in列表的值类型必须一致或兼容
*is null:查询为空的字段(或者不为空的),不能用=,<>来判断.
1)where 字段 is null;
2)where 字段 is not null;
*<=>(安全等于):可以判断null的值,也可以判断普通的数值,但是可读性较低.
语法:where salary <=> 12000;

上一篇:Codeup100000575问题 E: Shortest Distance (20)


下一篇:java8 时间处理速查笔记