• MYSQL统计


    mysql统计同一字段下,不同值的总数的方法:

    basebandBoard为字段,BPN2和CCE1等是为字段的多个值,这里进行统计。

    方法一:

    use gc;
    select basebandBoard,count(basebandBoard) co from four where basebandBoard='CCE1';
    select basebandBoard,count(basebandBoard) co from four where basebandBoard='BPN2';
    select basebandBoard,count(case when basebandBoard='BPN2' then 1 end) as BPN2,
    count(case when basebandBoard='CCE1' then 1 end) as CCE1,
    count(case when basebandBoard='BPP1' then 1 end) as BPP1
    from four
    group by basebandBoard;

     效果:

    方法二:

    select count(if(basebandBoard='BPN2',basebandBoard,null)),count(if(basebandBoard='CCE1',basebandBoard,null)),count(if(basebandBoard='BPP1',basebandBoard,null)) from four;

    效果:【这样的显示可以有助于知道if的用法,后续实际使用可以取别名】

    命别名后:

    select count(if(basebandBoard='BPN2',basebandBoard,null)) BPN2,count(if(basebandBoard='CCE1',basebandBoard,null)) BPN2,count(if(basebandBoard='BPP1',basebandBoard,null)) BPP1 from four;

    效果:

  • 相关阅读:
    kvm
    docker及lvs负载
    zookeeper,及k8s基础概念
    zabbix-proxy及ELK
    gitlab及jenkins
    绘图 Matplotlib Numpy Pandas
    Elasticsearch
    Git命令小结
    win黑窗口命令
    Linux基础命令
  • 原文地址:https://www.cnblogs.com/ciscolee/p/11178864.html
Copyright © 2020-2023  润新知