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: 基本概念 哈希表在实践中使用的非常广泛,例如编译器通常会维护 ...
随机推荐
- POJ 3087 Shuffle'm Up(模拟退火)
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- windows server 2003中端口默认不能使用问题
问题:在windows server 2003中IIS6.0新建站点,给了一个新端口(非80),然后配置好后不能访问 解决方案:系统内置防火墙需要添加对应端口,如下图: 即解决.
- NGUI中获取鼠标在控件内部坐标
在UIWidget 中添加以下函数.获得的坐标系是以右上角为原点坐标,x轴向左,一轴向下. public Vector2 GetTouchPoint() { Vector3 p0 = cachedT ...
- 多线程-Thread,Runnable,Callable,Future,RunnableFuture,FutureTask
类图: 先看各自的源码: public interface Runnable { public abstract void run(); } public class Thread implement ...
- [转]AngularJS ui-router (嵌套路由)
本文转自:http://www.oschina.net/translate/angularjs-ui-router-nested-routes http://www.codeproject.com/A ...
- vue的单文件组件
五. 单文件组件 1. .vue文件 .vue文件,称为单文件组件,是Vue.js自定义的一种文件格式,一个.vue文件就是一个单独的组件,在文件内封装了组件相关的代码:html.css.js .vu ...
- 地址url的split()方法使用;
stringObject.split(separator,howmany) 参数 描述 separator 必需.字符串或正则表达式,从该参数指定的地方分割 stringObject. howmany ...
- 什么是BOM
什么是BOM BOM(byte-order mark),即字节顺序标记,它是插入到以UTF-8.UTF16或UTF-32编码Unicode文件开头的特殊标记,用来识别Unicode文件的编码类型.对于 ...
- spring junit 部署两套测试方案
第一套方案: 1.初始化application:使用@ContextConfigurationr的classpath属性,如 @ContextConfiguration(locations = { & ...
- c# 获取Excel内容的分析
现在主流的Excel文档有2003和2007 c#获取 Excel2003 连接字符串 string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; ...

