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("梅超風(fēng)",'女',38,'江南'),("梅用",'男',35,'南京'),("馬超",'男',25,"西涼");
select * from student where name like "%用";
select * from student where name like "%"; #匹配所有的數(shù)據(jù)
select * from student where name like "_超%";
select avg(age) from student; -- 求平均數(shù)
select count(1) from student;-- 求條數(shù)
select count(*) from student;-- 求條數(shù)
select max(age) from student; -- 求最大值
select min(age) from student; -- 求最小值
select sum(age) from student; -- 求和