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;

 

转载于:https://www.cnblogs.com/sunny0/p/8944383.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值