一、增

insert into student(name, age) values('tom', 20);
insert into student(name, age) values('tom', 18),('joker', 18);
insert into student(name, age) select name, age from info;

二、删

delete from db1;
delete from db1 where 条件判断
delete from db1 where 条件判断 and 条件判断
delete from db1 where 条件判断 or 条件判断
条件判断
= !=
< <=
> >=
truncate table db1;

三、改

update db1 set name = 'master';
update db1 set name = 'joker' where age = 20;

四、查

前面
select * from db1;
select name,age from db1;
select name as n, age from db1; 别名
select name,1 from db1;
条件
select * from tb1 where name = 'tom'; # 条件判断
select * from tb1 where name = 'tom' and age >1;
select * from tb1 where name = 'tom' or name = 'joker';
select * from tb1 where name in ('tom', 'joker')
select * from tb1 where name not in ('tom', 'joker');
select * from tb1 where id between 1 and 5; # 闭区间
select * from tb1 where id in(select id from info);
通配符
select * from tb1 where name like 'a%';
select * from tb1 where name like 'a_';
注意:% 匹配任意字符,_ 匹配一个字符
分页
select * from tb1 limit 位置, 长度; # 若limit后面,只有一个参数,则是长度
select * from tb1 limit 长度 offset 位置;
排序
select * from tb1 order by id asc;
select * from tb1 order by id desc;
分组
select count(cid), caption from class group by caption;
select count(cid), caption from class where id > 5 group by caption having count(cid) >1;
聚合函数: max(列) min(列) sum(列) avg(列) count(列) 计算
注意:对聚合函数的结果进行比较要使用 having 相当于 where, where 在 最前面
连表操作
select * from userinfo1,department where userinfo.id=department.d_id;
# 不常用
select * from userinfo
left join department on userinfo.id=department.d_id;
# 左边全显示,右边没有补NULL
select * from userinfo
inner join department on userinfo.id = department.d_id;
# 不显示NULL
select * from userinfo
right join department on userinfo.id = department.d_id;
# 右边的全显示,左边没有补NULL 注意:left join, right join, inner join, 都用on ',' 用where
前面的列,若是表有相同的列 表名.列名 来表示

补充

1.distinct 有去重的效果,但最好不要使用,效率低
  select distinct username from userinfo;
2.查询多个表,会出现笛卡尔积现象
3.映射可以是查询语句
  select (select name from info) from userinfo;
4.条件语句
  case when 条件 then 为True else 为false end
6.判断是否为空
  if(isnul(数据), 0, 1)
7.unoin
  上下链表,注意列要一样
  具有去重的作用,union all不去重
select * from userinfo
union
select * from info;

mysql 行增删改查的更多相关文章

  1. MySQL数据库(增删改查语句)

    MySQL数据库(增删改查语句)一.登录数据库:---->  mysql -uroot -proot;(对应用户名和密码)二.SQL语句:    数据定义语言DDL  用来定义数据库.表.列,关 ...

  2. Asp.Net操作MySql数据库增删改查

    Asp.Net操作MySql数据库增删改查,话不多说直接步入正题.git源码地址:https://git.oschina.net/gxiaopan/NetMySql.git  1.安装MySQL数据库 ...

  3. MySQL之增删改查之

    MySQL之增删改查   前言:以下是MySQL最基本的增删改查语句,很多IT工作者都必须要会的命令,也是IT行业面试最常考的知识点,由于是入门级基础命令,所有所有操作都建立在单表上,未涉及多表操作. ...

  4. MySql之增删改查 · YbWork's Studio

    前提:在进行"增删改查"的操作之前,先建立一个包含数据表student的数据库(具体操作可以见MySQL之最基本命令): 1."增"--添加数据 1.1 为表中 ...

  5. Java连接MySQL数据库增删改查通用方法

    版权声明:本文为博主原创文章,未经博主允许不得转载. Java连接MySQL数据库增删改查通用方法 运行环境:eclipse+MySQL 以前我们Java连接MySQL数据库都是一个数据库写一个类,类 ...

  6. python操作mysql数据库增删改查的dbutils实例

    python操作mysql数据库增删改查的dbutils实例 # 数据库配置文件 # cat gconf.py #encoding=utf-8 import json # json里面的字典不能用单引 ...

  7. Mysql 的 增删改查

    mysql的增删改查 1:新建数据库 create database 数据库名 [其他选项]; 2:新建数据表 create table students ( id int unsigned not ...

  8. MongoDB学习-->命令行增删改查&JAVA驱动操作Mongodb

    MongoDB 是一个基于分布式文件存储的数据库. 由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关 ...

  9. 使用MySQL练习增删改查时因为版本问题出现连接错误

    使用MySQL练习增删改查时出现连接错误,错误提示如下: 2020-02-19 19:53:51.088 ERROR 16328 --- [reate-249798694] com.alibaba.d ...

随机推荐

  1. Argus--[优先队列]

    Description A data stream is a real-time, continuous, ordered sequence of items. Some examples inclu ...

  2. 【t091】油滴扩展

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 在一个长方形框子里,最多有N(0≤N≤6)个相异的点.在其中任何一个点上放一个很小的油滴,那么这个油滴 ...

  3. 【codeforces 749A】Bachgold Problem

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  4. CSS多余文本省略号显示

    CSS多余文本省略号显示 本次案例代码是在 elementui 当中的 table 组件中实际需求 当然使用的是纯 CSS3 代码,所以原生支持度高,兼容性高,所以可多场景应用 对于过长文本进行单行省 ...

  5. phpcms V9自定义分页函数

    大家做网站的时候,可能很多时候分页样式都得根据模板的要求来控制的,这时很多人都会去修改全局文件phpcms\libs\functions\global.func.php里的pages()函数,这样问题 ...

  6. UE4 学习

    1.官方文档:https://docs.unrealengine.com/en-US/index.html 2.入门教程: (1)C++ 程序员如何入门 UE 4:https://blog.csdn. ...

  7. 19.python基础试题(三)

    转载: 老男孩 Python 基础知识练习(三):https://www.cnblogs.com/nulige/p/6128674.html 1.列举布尔值为 False 的值空,None,0, Fa ...

  8. CodeForces - 559C

    学到了学到了,逆元求组合数还有贼神仙的计数DP 太强了! 难受啊

  9. redis 本地安装

    1.redis介绍 Redis是有名的NoSql数据库,一般Linux都会默认支持.但在Windows环境中,可能需要手动安装设置才能有效使用.简单介绍一下Windows下Redis服务的安装方法. ...

  10. Java工程师阅读源码的一些见解

    一.为何阅读源码 就是说,通过阅读源码能给你带来什么好处. 学习如何从需求-设计-实现,开阔你的思维,提升你的架构设计能力: 帮助更好地理解原理和架构设计: 帮助更快地定位线上问题BUG 可以根据自己 ...