mysql高级删除_MySQL之高级增删改查一
一、select all/distinct 字段名/别名 from table where条件+【1】+【2】+【3】;
where条件:>,<,≥,≤,like,between and(闭区间),in ,not in,与&&,或||,非!
all:查询去全部
distinct:去掉重复的结果
【1】:group by 【asc/desc】 asc:升序,desc:降序
【2】:order by
【3】:limit limit 3:取前3条记录;limit 2,3:从第三条记录开始,共取3条记录(从位置2开始,length为3)----可以用来分页
1、举例演示
先建一个表,id为主键(primary key),且自增长(auto_increment)
create table testabc (id int primary key auto_increment,name varchar(4));
添加数据
insert into testabc set name=a;
批量添加
insert into testabc (name) values (a),(b),(c),(c),(a),(a);
select * from testabc where name=a;
select * from testabc group by name;
限制前3个 select * from testabc limit 3;
select * from testabc limit 2,3; 从第三条记录开始,共取3条记录(从位置2开始,length为3)
二、常用函数max(),min(),avg(),count(),count()---记录值为NULL时不统计入数
1、举例演示,表如下
select max(age) from stu;
select sex, count(*) from stu group by sex;
select sex,count(*),max(age),avg(age) from stu group by sex;
一、select all/distinct 字段名/别名 from table where条件+【1】+【2】+【3】; where条件:>,<,≥,≤,like,between and(闭区间),in ,not in,与&&,或||,非! all:查询去全部 distinct:去掉重复的结果 【1】:group by 【asc/desc】 asc:升序,desc:降序 【2】:order by 【3】:limit limit 3:取前3条记录;limit 2,3:从第三条记录开始,共取3条记录(从位置2开始,length为3)----可以用来分页 1、举例演示 先建一个表,id为主键(primary key),且自增长(auto_increment) create table testabc (id int primary key auto_increment,name varchar(4)); 添加数据 insert into testabc set name=a; 批量添加 insert into testabc (name) values (a),(b),(c),(c),(a),(a); select * from testabc where name=a; select * from testabc group by name; 限制前3个 select * from testabc limit 3; select * from testabc limit 2,3; 从第三条记录开始,共取3条记录(从位置2开始,length为3) 二、常用函数max(),min(),avg(),count(),count()---记录值为NULL时不统计入数 1、举例演示,表如下 select max(age) from stu; select sex, count(*) from stu group by sex; select sex,count(*),max(age),avg(age) from stu group by sex;