用于只记得部分关键字的查询
查询姓名中以“小”字开头的姓名
select name from students where name='小';
select name from students where name like '小%';
select name from students where name like '小_';
查询带“小”字的名字
select name from students where name like '%小%';
查询三个字的名字
select name from students where name like '___';
查询最少有2个字的名字
select name from students where name like'__%';
查询以“李”开始的名字
select name from students where name rlike '^李.*';
查询以“李”开始,以“白”结束的名字
select name from students where name rlike '^李.*白$';
查询年龄从12到24之间的同学
select name, age from students where age between 12 and 24;
查询年龄不在12到14之间的同学
select name, age from students where age not between 12 and 24;
查询年龄为18、25、65的同学
select name, age from students where age=18 or age=25 or age=65;
-- 等价于
select name, age from students where age in (18, 25 , 65);
查询年龄不是18、25、65之间的同学
select name, age from students where age not in (18, 25 , 65);
判断身高信息为不空的同学
select *from students where height is not null;
查询身高信息为空的同学
select *from students where height is null;
作用:是查询出来的数据以某种规则呈现
order by 字段
查询身高在170到180之间的男性,并按照年龄从小到大排序
select name, height from students where (height between 170 and 180) and gender=1 order by age asc;
查询年龄在25到35之间的女性,并按照身高从高到低排序
select name, age,height from students where (age between 25 and 35) and gender=2 order by height desc;
order by 多个字段
查询年龄在25到65岁之间的男性,身高从低到高排序,如果身高相同的情况下按照id从大到小排序
select *from students where (age between 25 and 65) and gender =1 order by height asc, age desc;
按照id 从大到小,年龄从小到大,身高从高到低排序
select *from students order by id desc, age asc,height desc;