zoukankan      html  css  js  c++  java
  • 模糊匹配/聚合函数

    模糊匹配
     
    like
    %表示任意多个任意字符
    _表示一个任意字符
    例7:查询姓黄的学生
    select *from student where  name  like ’黄%‘
    例8:查询姓黄并且“名”是一个字的学生
     
    select *from student where  name  like ’黄_‘
     
    范围查询 
    in表示在一个非连续的范围内
    select *from student where id in (1,3,8);
     
    between  .... and.... 表示在一个连续的范围内----查询3-8的学生
    select *from student where  id between   3 and  8;
     
    判断非空   is  not    null
    查询填写了身高的学生
    select *from student  where height  is  not  null;
     
    优先级
    由高 到低的顺序为,小括号,not, 比较运算符, 逻辑运算符,如果and 比or  先运算,如果同时出现先算or 需要结合()包含字段
     
     聚合函数
    max()
    min()
    count()
    sum()
    avg()
    group by 子句(分组);按照属性名指定的字段进行分组。
    having子句(筛选):有 group by 才能 having 子句,只有满足条件表达式中指定的条件才能输出。
    order by子句(排序):按照“属性名”指定的字段进行排序。排序方式由“asc”和“desc”两个参数指出,默认是按照“asc”来排序,即升序。
    limit(限制结果集)。eg;limit 0,3;前面是从0开始,后面是几个
    随机列出来3个
    select *from student order by rand()limit 0,3;
    order by 字段 asc 或者 desc
     
    默认按照列值从小到大排列(asc)
    asc从小到大排列,即升序
    desc从大到小排序,即降序
    例1:查询学生信息,按学号降序
    select * from student order by id desc
     
    GROUP_CONCAT()函数
     函数的值等于属于一个组的指定列的所有值,以逗号隔开,并且以字符串表示。
    mysql> select teamno,group_concat(playerno)
        -> from MATCHES
        -> group by teamno;
    +--------+------------------------+
    | teamno | group_concat(playerno) |
    +--------+------------------------+
    |      1 | 6,6,6,44,83,2,57,8     |
    |      2 | 27,104,112,112,8       |
    +--------+------------------------+
    2 rows in set (0.01 sec)
    如果没有group by子句,group_concat返回一列的所有值
     
    with rollup子句:用来要求在一条group by子句中进行多个不同的分组
    select name,count(*))
  • 相关阅读:
    Spring的历史和哲学
    CORS简介
    LDAP概念了解
    Restful levels&HATEOAS
    python/mysql connector
    Session&Cookie 简介及使用
    XML简介
    Json简介
    《魅族官网》
    期末设计部分代码截图
  • 原文地址:https://www.cnblogs.com/liang715200/p/10021433.html
Copyright © 2011-2022 走看看