mysql基础2

March 9, 2022 by Clyde

create table teacher(
id int primary key auto increment,
name varchar(20) not null,
gender varchar(5) not null,
age int;
);

auto_increment 自动增长

insert into tracher(id,name,gender,age) values(1,'leon','man',18);
因为auto_increment是自动增长
insert into teacher(name,gender,age) values('leon','man',18);
也可以不写字段称呼
insert into teacher() values('leon','man',18);
添加多数据
insert into student(id,name,grade,email) values(1,'leon',88,'[email protected]'),(2,'aida',108,'[email protected]');

简单查询 查询字段
select * from 表名
select 字段,字段2 from 表名

条件查询
select * from kcb where kch>3;
select * from kcb where kcm='huaji';

与或非
select * from kcb where kch>3 or kcm='huaji';
select * from kcb where kch>3 and kcm='huaji';
select * from kcb where not kcm='huaji';

模糊搜索
select from kcb where kcm like '滑'; //滑后面很多字
selecet * from kcb where kcm like '滑_'; //滑后面一个字

集合搜索
select * from kcb where kch in(1,2,3);
select * from student1 where grade not in(108); //查询成绩没有在108
当成绩非空
select * from student1 where grade is not null;
取大于等于或者小于等于
select * from student1 where grade between 小的 and 大的
select * from student1 where grade>=18 and grade<=21;

asc升序 desc降序
select * from student1 order by grade asc;

统计个数count
select count(*) from student1;

统计最大值max 最小值min 平均值avg 和sum
select max(grade),min(grade),avg(grade),sun(grade) from student1 where id=1;

修改成绩表
update student set grade=grade-2;
当是张三
update student set grade=grade-2 where name='张三';
删除某一数据
upadte student set grade=null where id=1;

删除成绩表
delete from student where grade=108;

如需评论,请填写表单。

提交前先勾选

© 2024 | The Asuna Blog From | X-ways theme