美文网首页
2019-05-15Mysql 约束

2019-05-15Mysql 约束

作者: 纪绘 | 来源:发表于2019-05-16 20:37 被阅读0次

    1、查询的逻辑运算符(掌握)

    查询age大于35且性别为难的学生

    select * from student3 where age>35and sex='男’

    select * from student3 where age > 35 && sex = '男'

    查询age大于35或性别为男的学生(两个条件其中一个满足)

    select * from

    student3 where age > 35 or sex = '男'

    -- 查询id是1或3或5的学生

    -- 方式1:

    select * fromstudent3 where id = 1 or id =3 or id = 5;

    -- 方式2 :使用in 在里面格式:in(值1,值2,值3,...)

    select * fromstudent3 where id in(1,3,5);

    select * fromstudent3 where id =(1,3,5);

    -- 说明:什么情况下使用in?什么情况下使用=

    --=表示一个值 in一般是多个值或者一个值

    -- 在开发中就用in

    -- 需求:查询age是55的同学

    select * fromstudent3 where age = 55;

    select * fromstudent3 where age in(55);

    -- 查询id不是1或3或5的学生

    select * from student3 where id not in(1,3,5)

    2.查询_在什么区间

    查找english成绩大于等于75,且小于等于90的学生

    select *from student3 where english>=75 and english<=90;

    --另一个写法 格式:between 值1 and值2 要求值1小于值2

    select *from student3 where english between 75 and 90;

    3.模糊查询(掌握)

    使用的关键字是like

    语法:

    like '查询的字符‘

    对于模糊查询中的有两个特殊的符号。

    %表示大于等于0个任意字符

    _表示一个字符

    4.排序(掌握)

    1.按照一列进行排序

    --查询所有的数据,使用年龄降序排序

    select *from student3 order by age desc

    2.按照多列排序

    select *from 表名 order by 字段1 asc/desc,字段2asc/desc,字段3asc/desc。

    按照多列排序的时候从左向右依次排序,只有前面相同才可以按照后面进行排序

    5.聚合函数(掌握)

    针对列,根据列统计行。用来统计的。

    Count(列名)统计表中具有多少行数据

    说明:对于count聚合函数,开发中一般建议写*

    Sum(列名)对某一列进行求和

    Max(列名)求某一列最大值

    Min(列名)求某一列最小值

    Avg(列名)求某一列平均值

    注意:上述所有的聚合函数对于null都不作为统计

    总结

    1.能够使用SQL语句进行排序

    select字段from表名where条件order by 字段[ASC|DESC];

    ASC:升序

    DESC:降序

    1.能够使用聚合函数

    count:统计数量

    sum:求和

    max:获取最大值

    min:获取最小值

    avg:获取平均值

    3.能够使用SQL语句进行分组查询

    select字段from 表名 where条件group by 字段;

    分组是将相同数据一组


    相关文章

      网友评论

          本文标题:2019-05-15Mysql 约束

          本文链接:https://www.haomeiwen.com/subject/dafvaqtx.html