DQL条件查询(where)
查询为空is null
#使用'is'而不是'='
select * from workers where idCard is null;
查询非空is not null
select * from workers where idCard is not null;
!=的其他表示方法<>
select * from workers where age <> 90;
查询数据范围
#格式
select * from 表名 where 字段 between 最小值 and 最大值;
如果最小值>最大值, 查询不到结果
# BETWEEN AND
select * from workers where age BETWEEN 15 AND 99;
#
select * from workers where age>=15 and age<=99;
#
select * from workers where age>=15 && age<=99;
#BETWEEN 最小值 AND 最大值
#如果最小值<最大值,查询不到结果
select * from workers where age between 100 and 10;
或
select distinct * from workers where age=18 or age=20 or age=100;
# in+列表
select distinct * from workers where age in(18,20,100);
模糊查询
#查询名字长度为2的员工
select * from workers where name like '__';
#查询名字长度为3的员工
select * from workers where name like '___';
#身份证最后一位是'X'的员工
select * from workers where idCard like '%X';#百分号,代表任意的字符
#写了17个下划线... (每个下划线代表1个字符)
select * from workers where idCard like '_________________X';
标签:workers,查询,MYSQL,DQL,null,where,age,select
From: https://www.cnblogs.com/HIK4RU44/p/18062003