Mysql基本语句

新建库

create database  库名 default charset utf8  collate utf8_general_ci;

删除库

drop database  库名;

新建表

create table 表名(

字段名   类型(长度) primary key(主见)  comment  '注释',

字段名 类型(长度) comment  '注释',

字段名 类型(长度) comment  '注释'

);

清空表

truncate   table   表名;

删除表

drop  table  表名

插入数据(增加数据)

insert   into  表名   (字段1,字段2) value (数值1,数值2),(数值1,数值2)

insert  into  students 

(id,name,age,sex)

value 

(2,'张三',18,'男');

删除数据

delete   from  表名  where  限定条件;

更新数据

update  表名  set   字段名=数值    where   限定条件;

查询全部

select  * from   表名;

查询限定数据

select  字段名   from  表名    where   限制条件

模糊查询

like  '%字符%' ,%代表多位

select  *from   表名    where  name   like   '%马%'

between   and  语句

select *from   students   where   age   between  20  and   30;

最小值

select  min(age)   mins(起别名)  from  表名;

最大值

select max(age)  maxs  from  表名;

平均值

select   avg(age)    from   表名;

计算个数

select  count(age)   from  表名;

select   count(1)   from 表名;

去重

select   distinct   字段名  from    表名;

排序(asc:从小到大   desc:从大到小)

select   *from   表名    order  by   字段名;

select    字段名   from   表名    order  by   字段名;

分组

select  *from  表名   group   by  字段名;

select   字段名1   from  表名   group   by  字段名1;

去重后记录每组个数

select   字段名1, count(1)    from  表名  group  by  字段名1;

select   age, count(1)    from  表名  group  by  age;

去重后统计其他字段平均值、(最大值、求和)

select  字段名1,avg(字段名2)   from  表名   group  by  字段名1;

select  age,avg(salary)   from  表名   group  by  age;

男女中年龄最大值

select  sex,max(age)  from  表名   group  by  sex;

男女中人数

select  sex,count(age)  from  表名   group  by  sex;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值