• SQL------聚集函数


     首先你要知道 where->group by->having->order by/limit  ,这个就是写sql语句时的顺序

    5种常用的聚集函数

      MAX    求最大

      MIN    求最小

      SUM        求和

      AVG   求平均

      COUNT     计算总行数

    注意:聚集函数不支持父子关联。例如:

    Drop TABLE if exists t1;

    drop table if exists t2;

    create table t2(a int, b int, c int);

    insert into t2 values(1,2,3);

    insert into t2 values(2,2,2);

    insert into t2 values(2,2,2);

    insert into t2 values(3,2,2);

    commit;

    select b, c case when c > (select avg(t.b) from t2 ) then 1 else 0 end as d from t2 t group by c, b order by 1;   --该语句正常执行结果是要报错的。报错是正常的,不报错则有问题。

    drop table if exists t2;

  • 相关阅读:
    vim命令大全
    window 杀掉占用端口号
    Elasticsearch 后台启动
    排列组合2
    java 排列组合
    【MySQL】索引知识
    【jsoup】html解析
    【Rust】库 crate
    【VUE】chang事件传参
    【Rust】模块
  • 原文地址:https://www.cnblogs.com/kennyael/p/9938784.html
Copyright © 2020-2023  润新知