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. unity, 判断可见性

    如果一个物体被unity判定为”退一万步讲也一定不可见“,则unity不会去渲染它,但是如果我们给此物体添加了逻辑,这个逻辑仍然会被执行. 因此,假如这个逻辑是巨耗性能的逻辑,比如说”mesh的每个顶 ...

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

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

  3. matplotlib之极坐标系的极径网格线(rgrids)的显示刻度

    matplotlib之极坐标系的极径网格线(rgrids)的显示刻度 #!/usr/bin/env python3 #-*- coding:utf-8 -*- #################### ...

  4. POJ 1962-Corporative Network (并查集)

    题目有2种操作, 一种是查询,一种是设置. 设置为将u的父亲设置为v,然后他们之间的距离为|u-v|%1000 查询为该点到根点的距离 用并查集做,做的时候注意维护即可,注意取余操作. 代码: #in ...

  5. 微信中调起qq

    http://wpa.qq.com/msgrd?uin={$qq}&menu=yes

  6. target="_blank" 导致的钓鱼攻击

    挺久的漏洞,之前没仔细看现在看了下 直接构建实验环境: test1.html: <!DOCTYPE html> <html> <head> <meta cha ...

  7. Jenkins ssh 部署war到tomcat 虚拟目录

    1>完成Jenkins服务环境的搭建,此处不再详述,不会的童鞋可参考下面的博客 http://www.cnblogs.com/zz0412/tag/jenkins/ 2>安装Publish ...

  8. 怎么来爬取代理服务器ip地址?

    一年前突然有个灵感,想搞个强大的网盘搜索引擎,但由于大学本科学习软件工程偏嵌入式方向,web方面的能力有点弱,不会jsp,不懂html,好久没有玩过sql,但就是趁着年轻人的这股不妥协的劲儿,硬是把以 ...

  9. 在oschina添加了x3dom的索引

    http://www.x3dom.org/ http://www.oschina.net/p/x3dom x3dom的思路非常优秀并且可行,借助于WebGL的春风,将X3D带到了死而复生的境地.

  10. VM下redhat9.0不能上网

    近期本人在学习linux时,安装Red Hat Linux9后,可是上不了网,弄得查资料还得切换到虚拟机上去,特耗时间.还好没有疯掉! 首先,测试下你的linux看是否是这类问题,输入ping www ...