• linux数据库2


    ------------恢复内容开始------------

    day3 数据类型

    默认的是有符号 (unsigned变为无符号)

    int   有符号(负---正)  无符号(正整数)

    tinyint   小整数  -128---127   0---255

    smallint 大整数

    float 单精度  保留七位

    double 双精度  保留到14位

    字符串

        char(8) 0-255 括号里面的数字表示字符的个数

            定长,以空间换时间查询速度快,但是占空间

       varchar(10) 六位数

           变长,以时间换空间,占用空间少,相对速度慢

      text

    日期类型

    datetime  “2000-01-01 10:10:10"

    date ”2000-01-01“

    time ”10:10:10"

    year   2000  插入数据可以不加括号

    枚举类型与集合类型

    enum() 单选 sex 男 女 enum(“male","female")

    set()  多选 hobby set(”篮球“,”足球“)   ”篮球,足球”

    单表查询

    from

    where

    group by

    聚合函数(max(id)等)

    having

    select

    distinct

    order by

    limit

    group by

        有重复数据

       分组  分组之后的字段和聚会函数可以出现在select后面其他字段一律不能单独出现

         select age,group-concat(name) from c19 where age=19 group by age

    想要出线其他字段用 group-cancat函数

    聚合函数

    max()   求最大值

    min()   求最小值

    count()  求总个数

    avg()   求平均值

    sum() 求和

    day4 约束

    建立一张表

    字段id name sex枚举类型  birth——d(要求date)

    主键自增 唯一 默认值male  

    插入三条数据

    约束

    not null 不为空

    default 默认值

    unique key 唯一值

    primary key auto——increment(和主键配合使用)

    foreign key 外键

    day 单表查询


    查询20-50之间的信息

    select name,age from employee where age between 20 and 50;

    年龄是18或28或30的员工信息

    select * from employee where age in(18,28,30);

    找年龄里面含有8的员工姓名

    select * fromemployee where age like “%8%”

    部门里面含有a的部门

    select * from employee where post like “%a%“

    where子句中可以使用

    比较运算符 >,<,>=,<=,!=

    between 80 and 100 值在八十到100之间

    in(80,90,100)值是80或90或100

    like ”xiaopet“ pat可以是%或者_

      % 小时任意多字符,表示一个字符x%,a% %t

    逻辑运算符

    在多个条件可以直接使用逻辑运算符and or not

    小窍门:

    每这个字后面的字段,就是我们分组的依据

    group by

    where 都优先级比having的高

    where是不能用聚合函数作为条件

    having可以用聚合函数作为条件

    having 可以放到group by之后,而where只能放到group by之前。

    每个部门员工人数大于三个的部门

    order by 排序

    asc 升序默认是升序

    desc 降序

    select * from employee order by age desc

    limit 限制显示条数

    limit 3 limit0,3 相同

    limit 2,3 表示 从索引为2(第三条)开始,显示三条

    . 男员工的平均薪资,女员工的平均薪资
    select avg(salary),sex from employee group by sex;
    select avg(salary),sex from employee where sex="male"
    select avg(salary),sex from employee where sex="female";
    每个部门的所有薪水
    select sum(salary),post from employee group by post;
  • 相关阅读:
    Salesforce 大数据量处理篇(一)Skinny Table
    salesforce零基础学习(九十九)Salesforce Data Skew(数据倾斜)
    将博客搬至CSDN,新地址见此文章内容
    Spring Boot
    SpringBoot的模块及结构
    不建议现场注入– Spring IOC
    程序员健康指南
    如何使用Chrome DevTools花式打断点
    这堂课一上40年, 他告诉学生:就算你进了麻省理工, 不懂这个也很难成功!
    非对称加密算法--RSA加密原理
  • 原文地址:https://www.cnblogs.com/yuzui/p/12548463.html
Copyright © 2020-2023  润新知