模糊查询笔记

create database Tow20210603 default charset=utf8;
use Tow20210603;

create table student(
name varchar(10),
sex char ,
age int,
address varchar(100)
);

insert into student values ("王小小","男",20,"许昌");
insert into student values ("王大","男",20,"许昌");
insert into student values ("王二","男",20,"许昌");
insert into student values ("王八","男",20,"许昌");
insert into student values ("吴用","男",18,"沧州");
insert into student values ("吴勇","男",18,"曹县");
insert into student values ("吴汉","男",38,"安阳");

select * from student;

-- 模糊查询 like

% 匹配多个字符 _ 匹配一个字符

select * from student where name like "王%";
select * from student where name like "王_";
insert into student values("梅超风",'女',38,'江南'),("梅用",'男',35,'南京'),("马超",'男',25,"西凉");

select * from student where name like "%用";
select * from student where name like "%"; #匹配所有的数据
select * from student where name like "_超%";

select avg(age) from student; -- 求平均数
select count(1) from student;-- 求条数
select count(*) from student;-- 求条数
select max(age) from student; -- 求最大值
select min(age) from student; -- 求最小值
select sum(age) from student; -- 求和

你可能感兴趣的:(模糊查询笔记)