博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据库系列二
阅读量:4349 次
发布时间:2019-06-07

本文共 942 字,大约阅读时间需要 3 分钟。

一、索引

主键索引:primery key

唯一索引:unique key

全文索引:fulltext index

普通索引:index

 

二、关系:

一对一

一对多/多对一

多对多

 

三、主键冲突

更新:insert into 表名 values (值) on duplicate key update 字段 = 值

替换:replace into 表名 values (值)

 

四、更新、删除操作

限制更新:update 表名 set 字段 = 值 where 条件 limit 数量

限制删除:delete from 表名 where 条件 limit 数量

 

五、查询

1.查询所有结果:

select * from 表名

select all * from 表名

2.查询的结果去重:

select distinct * from 表名

 

3逻辑符

||   或

&&   且

!     非

between x and y  在X,Y之间

in  字段在列表里面

 

4.分组:group by 字段1 [,字段2]  asc/desc

asc/desc   正序/反序

用于统计:count,max,min,avg,sum

select 字段,count/max/min/avg/sum from 表名 group by 字段

分组后的所有该字段的数据

select 字段,group_concat(字段) from 表名 group by 字段

回溯统计

select 字段1 字段2 from 表名 group by 字段 with rollup

 

5.having

用于分组统计的结果进行条件判断

select 字段,统计字段 from 表名 group by 字段 having 条件

 

6.order by

排序,asc/正序,desc/反序

select 字段 from 表名 order by 字段1 [字段2] [asc/desc]

 

7.limit

限制结果的数量

select 字段 from 表名 limit 数量

select 字段 from 表名 limit 起始值,数量

转载于:https://www.cnblogs.com/st-st/p/9937118.html

你可能感兴趣的文章
关于String StringBuffer 和 StringBulider
查看>>
as3 sort
查看>>
STL传递比较函数进容器的三种方式
查看>>
hdu 2680 Choose the best route Dijkstra 虚拟点
查看>>
Python _ 开始介绍对象
查看>>
系统视图介绍
查看>>
第一次接触FPGA至今,总结的宝贵经验
查看>>
Ubuntu下libpcap安装步骤
查看>>
26. Remove Duplicates from Sorted Array java solutions
查看>>
[bzoj1185] [HNOI2007]最小矩形覆盖
查看>>
并发&并行 同步&异步 GIL 任务 同步锁 死锁 递归锁
查看>>
全景图制作详解
查看>>
React之todo-list
查看>>
cocoapods降级版本
查看>>
MYSQL复习笔记4-基本SQL语句
查看>>
C#&java重学笔记(函数)
查看>>
14软件G2班
查看>>
bzoj 1977 [BeiJing2010组队]次小生成树 Tree
查看>>
bzoj 2119 股市的预测——枚举长度的关键点+后缀数组
查看>>
从微信中跳到外部浏览器
查看>>