zoukankan      html  css  js  c++  java
  • SQL 基础整理

    • SQL语句执行顺序
    1. From
    2. 表连接
    3. on连接条件,形成新的虚拟表
    4. where 筛选条件
    5. group by 生成新的结果集合  group by 分组列表
    6. having 分组后筛选
    7. select 选出显示的
    8. order by 排序
    9. limit        分页/个数限制
    • 子查询顺序

      除了exists,先执行子查询,再外查询

      exists:相关子查询,先执行外查询,再根据子查询字段进行过滤。

    • 分页查询

      limit (page-1)*size,size

    • 字符控制函数

    substr('helloworld',1,5)  hello

    instr('helloworld','w')      6

    LPAD(salary,10,'*')        ****salary

    TRIM('H' from 'Helloworld') elloworld

    • 视图应用场景
      • 多个地方用到同样的查询结果
      • 该查询结果会用的SQL语句较复杂
    • DML 表操作 无table
    insert into tableName( column1,column2,...) values(值1,...)
    update student
    set age=18
    where  name='hwj'
    /* 表数据删除 */
    delete
    from student where age=18
    /* 多表 */
    delete from student s1,course c1
    where s1.class=c1.class
    and s1.name='mm';
    # 方式2
    truncate 语句
    truncate table student
    •  DDL 管理操作,对表操作要加上字段table
    # 创建
    create table if not exists student(column1,...)
    # 修改 字段名
    Alter table student change column 旧 新字段
    
    # 修改表名
    Alter table student rename to student1
    
    # 修改字段类型和约束
    Alter table tablename modify column column_name  约束
    
    # 添加字段
    Alter table 表名 Add column 字段;
    
    # 删除字段
    Alter table 表名 drop column 字段
    
    # 删除表
    drop table if exists 表名
    初晨暖阳,夜落星河。 少年披梦,远方有歌。 红黄之上,春夏晚风。 闲肆游走,人群熙攘。
  • 相关阅读:
    LeetCode 338. 比特位计数
    LeetCode 208. 实现 Trie (前缀树)
    初识restful api接口
    破解 Navicat Premium 12
    ES6 Reflect的认识
    ES6 WeakMap和WeakSet的使用场景
    sublime 注释模版插件DocBlockr的使用
    js call方法的使用
    ES6 Generator的应用场景
    ES6 Symbol的应用场景
  • 原文地址:https://www.cnblogs.com/alidata/p/13385590.html
Copyright © 2011-2022 走看看