• 数据库系列二


    一、索引

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

  • 相关阅读:
    ThinkPhp框架分页查询和部分框架知识
    tp框架增删改
    WAMP中mysql服务突然无法启动 解决方法
    thinkphp框架 的 链接数据库和操作数据
    php 全局使用laravel的dd和dump
    给centos装图形界面 widowsx
    marquee标签的使用
    微信公众号开发入门教程
    laravel admin引入css js报错 https
    利用Croppie裁剪图片并后台保存
  • 原文地址:https://www.cnblogs.com/st-st/p/9937118.html
Copyright © 2020-2023  润新知