数据库系列二

一、索引

主键索引: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 起始值,数量

posted @ 2018-11-09 20:45  st--st  阅读(144)  评论(0编辑  收藏  举报