1、增

语法:insert into 表 (列名,列名...) values (值,值...)

# 插入单条数据
insert into 表 (列名,列名...) values (值,值...)

# 插入多条数据
insert into 表 (列名,列名...) values (值,值...),(值,值...)

# 插入另一条语句的查询结果
insert into 表 (列名,列名...) select 列名,... from 表

2、删

语法:delete from 表

delete from 表;
delete from 表 where id=;

3、改

语法:update 表 set name = 'nick' where id>1

update 表 set name = 'nick' where id>

4、查

语法:select * from 表

select * from 表
select * from 表 where id >
select nid,name,gender as gg from 表 where id > # as 做别名

5、条件

语法:select * from 表 where id > 1

    select * from 表 where id >  and name != 'nick' and num = ;    # 多个条件
select * from 表 where id between and ; # id在5到16之间
select * from 表 where id in (,,); # id在元祖中
select * from 表 where id not in (,,); # id不在元祖中
select * from 表 where id in (select nid from 表); # id在查询结果中

6、通配符

语法:select * from 表 where name like '_n%'

  select * from 表 where name like 'ni%'  # ni开头的所有(多个字符串)
select * from 表 where name like 's_' # s开头的所有(一个字符)

7、限制

语法:select * from 表 limit 9,5;

    select * from 表 limit 5;            # 前5行
select * from 表 limit 9,5; # 从第9行开始的5行
select * from 表 limit 5 offset 9 # 从第9行开始的5行

8、排序

语法:select * from 表 order by 列1 desc,列2 asc

    select * from 表 order by 列 asc             # 根据 “列” 从小到大排列
select * from 表 order by 列 desc # 根据 “列” 从大到小排列
select * from 表 order by 列1 desc,列2 asc # 根据 “列1” 从大到小排列,如果相同则按列2从小到大排序

9、分组

语法:select num from 表 group by num

    select num from 表 group by num           # 根据num分组
select num,nid from 表 group by num,nid # 根据num和nid分组
select num,nid from 表 where nid > 10 group by num,nid order nid desc
select num,nid,count(*),sum(score),max(score),min(score) from 表 group by num,nid # 内置函数
select num from 表 group by num having max(id) > 10 # 前面计算的结果交由后面处理 注:group by 必须在where之后,order by之前
count(*)、count(1) # 表示个数
sum(score)   # 表示和
max(score)   # 表示最大数
min(score)   # 表示最小数 having # 要用前面处理结果是用having。

10、连表

语法:inner join . onleft join . onright join . on

    无对应关系则不显示
select A.num, A.name, B.name
from A,B
Where A.nid = B.nid 无对应关系则不显示
select A.num, A.name, B.name
from A inner join B
on A.nid = B.nid A表所有显示,如果B中无对应关系,则值为null
select A.num, A.name, B.name
from A left join B
on A.nid = B.nid B表所有显示,如果B中无对应关系,则值为null
select A.num, A.name, B.name
from A right join B
on A.nid = B.nid

11、组合

语法:union、union all

    组合,自动处理重合
select nickname
from A
union
select name
from B 组合,不处理重合
select nickname
from A
union all
select name
from B

参考:https://www.cnblogs.com/suoning/articles/5769141.html

mysql_表内容_操作的更多相关文章

  1. mysql(三) 数据表的基本操作操作

    mysql(三) 数据表的基本操作操作 创建表,曾删改查,主键,外键,基本数据类型. 1. 创建表 create table 表名( 列名 类型 是否可以为空, 列名 类型 是否可以为空 )ENGIN ...

  2. mysql_表_操作

    1.创建表 # 基本语法: create table 表名( 列名 类型 是否可以为空 默认值 自增 主键, 列名 类型 是否可以为空 )ENGINE=InnoDB DEFAULT CHARSET=u ...

  3. 第二百七十八节,MySQL数据库-表内容操作

    MySQL数据库-表内容操作 1.表内容增加 insert into 表 (列名,列名...) values (值,值,值...); 添加表内容添加一条数据 insert into 表 (列名,列名. ...

  4. MySQL数据库-表内容操作

    1.表内容增加 insert into 表 (列名,列名...) values (值,值,值...); 添加表内容添加一条数据 insert into 表 (列名,列名...) values (值,值 ...

  5. mysql_用户_操作

    一. 创建用户 登录MySQL mysql -u root -p 添加新用户 create user 'username'@'host' identified by 'password'; usern ...

  6. [刘阳Java]_MyBatis_其他方式来实现多表查询的操作_第9讲

    MyBatis其他方式来实现多表查询的操作 利用Java中的集合框架(List,Map) 其中List存储多个查询返回的记录 Map查询返回字段,同时记录表中一条数据 <?xml version ...

  7. OCM_第三天课程:Section1 —》表空间的操作和管理、服务配置

    注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...

  8. oracle表结构和表内容差异比对

    oracle表结构和表内容差异比对 oracle中有三种集合操作,他们会把左边和右边的select 结果集进行集合操作. union 并集 intersect 交集 minus 差集 假设有如下两张表 ...

  9. PHP数组/Hash表的实现/操作、PHP变量内核实现、PHP常量内核实现 - [ PHP内核学习 ]

    catalogue . PHP Hash表 . PHP数组定义 . PHP变量实现 . PHP常量实现 1. PHP Hash表 0x1: 基本概念 哈希表在实践中使用的非常广泛,例如编译器通常会维护 ...

随机推荐

  1. Lintcode---实现 Trie

    实现一个 Trie,包含 insert, search, 和 startsWith 这三个方法. 注意事项 你可以假设所有的输入都是小写字母a-z. 您在真实的面试中是否遇到过这个题? Yes 样例 ...

  2. idea lib下有jar包但是仍然报错 找不到类

    现象: idea lib下有jar包但是仍然报错 找不到类 但是有个奇怪现象 同样的配置下项目在eclipse中可以正常编译 启动. package com.puhui.car.aspect; imp ...

  3. atitit..国富论 在现代it企业项目管理中的作用attialx 总结---国富论读后感 attialx

    atitit..国富论 在现代it企业项目管理中的作用attialx 总结---国富论读后感 attialx 1. 国民财富的性质和原因的研究(简称:<国富论>) 1 2. 蕴含的重要管理 ...

  4. linux上定时备份mysql数据库

    定时备份数据库 /usr/sbin/backupmysql timestamp=`date +"%Y-%m-%d-%H-%M-%S"` mysqldump -uroot -p'12 ...

  5. HTTP基本认证(Basic Authentication)的JAVA实例代码

    大家在登录网站的时候,大部分时候是通过一个表单提交登录信息. 但是有时候浏览器会弹出一个登录验证的对话框,如下图,这就是使用HTTP基本认证. 下面来看看一看这个认证的工作过程: 第一步: 客户端发送 ...

  6. CentOs 7 安装总结

    1.安装 前几天安装了CentOs 7系统,弄了好几次都进不去图形安装界面,总是进入 "dracut:/# _".本以为是系统盘没做好,就用了另外几种工具重做了盘,还是一样.后来在 ...

  7. PHP学习笔记(15)PDO数据库操作+AJAX无刷新技术删除用户

    pdo.php <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  8. css断句 word-break

    word-break:break-all;word-wrap:break-word; 兼容IE6 火狐 chrome

  9. yii save model return id null

    /** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' ...

  10. C#版本的xUnit的测试框架模型和xUnit.NET开源项目

    1. 参考kent beck的测试驱动写的C#测试框架模型 a) 测试用例: WasRun, 基类为TestCase b) 框架: TestCaseTest用来测试TestCase,本身也是它的子类, ...