Mysql增删改查,分组查询,统计条数

  1. 模糊查询
    %张% 含有张
    select 列名 from 表名 where 列名 like ‘%张%’;
    张% 以张开头 可以是个n个字符
    select 列名 from 表名 where 列名 like ‘张%’ ;
    张_ 张开头 两个字符 张三 张四
    select 列名 from 表名 where 列名 like‘张_’;
  2. And 和
    Select * from 表名 where 列名=‘1’ and sex=‘1’;
  3. Or 或
    select * from 表名 where 列名 like '张%‘or 列名 like’李%’;
  4. 升序:selectfrom 表名 order by id asc;
    降序:select
    from 表名 order by id desc;
  5. 限制条数
    select * from 表名 limit 0,3;
  6. 判断某字段不为空
    select * from 表名 where 列名 is not null;
  7. 清空数据表 truncate table 表名;
  8. 删除表 drop table 表名;
  9. 删库 drop database 库名;
    sql:数据库与程序通讯的语言。
    insert into student2(sname,sex,card,phone,birthday,addtime,intro) values (‘222)’,null,null,null,null,null,null);

聚合函数
count(*) 统计数目
sum 求和
min 最小值
max 最大值
avg 平均值

select count(*) as ‘数量’,sex as ‘性别’ from
student2 where 1
group by sex //根据 sex 分组

select * from student2
where age between 15 and 28

条件
where 分组前的条件
having 对分组后的查询结果进行条件限制

SELECT COUNT(),sex FROM
student2 WHERE 1 AND age>14
GROUP BY sex
HAVING COUNT(
)>5

统计条数:
Select count(*) from 表名;
(列名)+最大值
Select max(列名)from 表名;
+平均值
Select avg(列名)from 表名;
+求和
Select sum(列名)from 表名;

Update 表名 set 列名;//默认全部
Update 表名 set 列名=1;//默认=1的
Select count(*)from student where sex=1;

Select count(*)as ‘数量’,sex as ‘性别’from
student where 1
Group by sex;//根据列名分组

Update student
set age=18 where sid<9//存年龄

select avg(age),sex from student//求平均年龄
where 1 group by sex //

select count(*) from(select ssex from student group by ssex//统计种)as a student where ssex

select sname,drgee from
student as s join score as c
on s.sno=c.sno

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值