美文网首页
MySQL笔记整理(二)

MySQL笔记整理(二)

作者: guaren2009 | 来源:发表于2020-05-11 17:56 被阅读0次

MySQL常用语法整理

一、增删改查

1.1、增

模板示例:

insert into 库名.表名(c1,c2,c3,c4) values(v1,v2,v3,v4);

示例:

insert into test.ruoze_t1(name,age) values ('张三',18);

1.2、删

模板示例:

delete from 库名.表名 where 。。。;

示例:

delete from test.ruoze_t1 where name='张三';

1.3、改

模板示例:

update 库名.表名 set c1=v1,c2=v2 where c3=v3;

示例:

update test.ruoze_t1 set age=33,name='小丽' where id=1;

1.4、查

select  c1 from 库名.表名 where c2=v2;

1.5、where条件过滤

select name , age from 库名.表名 where age =18;

select name , age from 库名.表名 where age >18;

select name , age from 库名.表名 where name in ('zhangsan','lisi');

select name , age from 库名.表名 where name not in ('zhangsan','lisi');

1.6、排序 

升序:select name , age  from 库名.表名 order by age;

降序:select name , age  from 库名.表名 order by age desc;

1.7、合并表

合并去重:select name,age from a union select name , age from b ;

合并不去重:select name , age  from a union all select name , age from b;

1.8、模糊查询

select name , age from 库名.表名 where name like '_三';

select name , age from 库名.表名 where name like '%三';

select name , age from 库名.表名 where name like '%三%';

1.9、null语法

select name , age from 库名.表名 where name is null;

select name , age from 库名.表名 where name is not null;

select name , ifnull(age,18) from 库名.表名;

1.10、聚合函数

select max(age),min(age),avg(age),count(1),sum(age) from 库名.表名

1.11、分组

分组并过滤:select name,age from 库名.表名 where age >18 group by sex having sum(age)<100;

1.12、子查询

select t.sex,t.age_avg  from (select sex,avg(age) as age_avg from 库名.表名 group by sex) t where age_avg>19;

相关文章

  • MySQL笔记整理(二)

    MySQL常用语法整理 一、增删改查 1.1、增 模板示例: insert into 库名.表名(c1,c2,c3...

  • MYSQL语句执行大体流程

    学习笔记是学习了 极客时间 - 《MySQL实战45讲》整理的笔记。 MYSQL简单架构 MySQL 可以分为 ...

  • MySQL 学习实践笔记(四)

    MySQL 学习实践系列 MySQL 学习实践笔记(一) MySQL 学习实践笔记(二) MySQL 学习实践笔记...

  • MySQL 学习实践笔记(三)

    MySQL 学习实践系列 MySQL 学习实践笔记(一) MySQL 学习实践笔记(二) MySQL 学习实践笔记...

  • MySQL 学习实践笔记(二)

    MySQL 学习实践系列 MySQL 学习实践笔记(一) MySQL 学习实践笔记(二) MySQL 学习实践笔记...

  • MySQL 学习实践笔记(一)

    MySQL 学习实践系列 MySQL 学习实践笔记(一) MySQL 学习实践笔记(二) MySQL 学习实践笔记...

  • MySQL索引(一)

    学习笔记是学习了 极客时间 - 《MySQL实战45讲》整理的笔记。 在 MySQL 中,索引是在存储引擎层实现...

  • 史上最全的mysql基础入门教程

    完整的demo和笔记整理传送门 启动与停止 启动mysql服务sudo /usr/local/mysql/supp...

  • MySQL Index 是如何工作的

    最近在读MySQL的技术内幕, MySQL的Index之前在MySQL读书笔记的混乱整理中简单提到过, 简单介绍了...

  • JDBC 编程学习

    前言 将最近学习的JDBC编程整理成笔记,做次记录。 mysql 安装 首先安装mysql 8.0.19 版本数据...

网友评论

      本文标题:MySQL笔记整理(二)

      本文链接:https://www.haomeiwen.com/subject/nksunhtx.html