mysql_表内容_操作
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 . on、left join . on、right 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_表内容_操作的更多相关文章
- mysql(三) 数据表的基本操作操作
mysql(三) 数据表的基本操作操作 创建表,曾删改查,主键,外键,基本数据类型. 1. 创建表 create table 表名( 列名 类型 是否可以为空, 列名 类型 是否可以为空 )ENGIN ...
- mysql_表_操作
1.创建表 # 基本语法: create table 表名( 列名 类型 是否可以为空 默认值 自增 主键, 列名 类型 是否可以为空 )ENGINE=InnoDB DEFAULT CHARSET=u ...
- 第二百七十八节,MySQL数据库-表内容操作
MySQL数据库-表内容操作 1.表内容增加 insert into 表 (列名,列名...) values (值,值,值...); 添加表内容添加一条数据 insert into 表 (列名,列名. ...
- MySQL数据库-表内容操作
1.表内容增加 insert into 表 (列名,列名...) values (值,值,值...); 添加表内容添加一条数据 insert into 表 (列名,列名...) values (值,值 ...
- mysql_用户_操作
一. 创建用户 登录MySQL mysql -u root -p 添加新用户 create user 'username'@'host' identified by 'password'; usern ...
- [刘阳Java]_MyBatis_其他方式来实现多表查询的操作_第9讲
MyBatis其他方式来实现多表查询的操作 利用Java中的集合框架(List,Map) 其中List存储多个查询返回的记录 Map查询返回字段,同时记录表中一条数据 <?xml version ...
- OCM_第三天课程:Section1 —》表空间的操作和管理、服务配置
注:本文为原著(其内容来自 腾科教育培训课堂).阅读本文注意事项如下: 1:所有文章的转载请标注本文出处. 2:本文非本人不得用于商业用途.违者将承当相应法律责任. 3:该系列文章目录列表: 一:&l ...
- oracle表结构和表内容差异比对
oracle表结构和表内容差异比对 oracle中有三种集合操作,他们会把左边和右边的select 结果集进行集合操作. union 并集 intersect 交集 minus 差集 假设有如下两张表 ...
- PHP数组/Hash表的实现/操作、PHP变量内核实现、PHP常量内核实现 - [ PHP内核学习 ]
catalogue . PHP Hash表 . PHP数组定义 . PHP变量实现 . PHP常量实现 1. PHP Hash表 0x1: 基本概念 哈希表在实践中使用的非常广泛,例如编译器通常会维护 ...
随机推荐
- .net 非阻塞事件获取返回异步回调结果
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- html5-canvas绘图操作方法
<script>function draw(){ var c=document.getElementById("mycanvas"); c.width=50 ...
- IOS 通过界面图标启动Web应用 + 全屏应用 + 添加到主屏幕
请注意!!!使用了[全屏模式之后].页面的顶部会空出一大块.而且这并不属于margin,padding,或者定位.就是单纯的空出来非常难调试.其实坑就是这里 在 iPhone「添加到主屏幕」时显示自定 ...
- Windows+Nginx+IIS做图片分布式存储详细步骤
最近几天,一直在学习nginx在windows平台下的使用,为了寻找几种大量图片分布式存储而且有相对简单的存储方案 nginx是一种,还找到一种MongoDB GridFS 这两种方案我还是比较中意的 ...
- 开启ss-libev多用户
原理:通过查看进程,得到命令及需要的参数,然后,在制作一个配置文件,pid文件随意写. 1.首先正常开启一个: /etc/init.d/shadowsocks-libev start 2.然后:利用查 ...
- G1日志分析
1. 概述 来自对官方G1垃圾收集器的日志解释分析,官方地址:https://blogs.oracle.com/poonam/understanding-g1-gc-logs或https://blog ...
- gpg: symbol lookup error
今天使用sudo apt-get 安装包的时候,出现gpg错误,如下: gpg: symbol lookup error: /usr/local/lib/libreadline.so.6: undef ...
- 使用 xlue 实现 tips
经常遇到如下的需求 鼠标hover到目标对象一定时间后,弹出tips或者窗口; 鼠标离开目标对象一定时间后,隐藏tips或者窗口; 鼠标从目标对象移动到弹出的窗口上,这种状况下不隐藏窗口; 考虑到这种 ...
- spring-webservice.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- jQuery插件学习笔记
近期在研究jQuery插件,插件编写的目的是给已经有的一系列方法或函数做一个封装,以便在其它地方反复使用,方便后期维护. JQuery除了提供一个简单.有效的方式进行管理元素以及脚本,它还还提供了例外 ...

