• MYSQL统计多个count_mysql 不同条件count ,多条件count()


    create table abc(A int,B int)
    
    Select A,count(B) as total from ABC group by A
    
    Select A,count(B) as total1 from ABC where B > 30 group by A
    
    Select A,count(B) as totlal2 from ABC where B > 20 group by A
    
    如何合并这三个查询?
    
    得到一个查询结果:
    
    A,total,total1,total2
    
    答:
    
    Select A,
    
    count(B) as total,
    
    sum(case when B > 30 then 1 else 0 end) as total1,
    
    sum(case when B > 20 then 1 else 0 end) as total2
    
    from ABC group by A
    
    自己的例子
    
    select  count(1)  from origin_crx_data  where create_time like '2019-02-23%' and source='12345'
    
    select  count(1)  from origin_crx_data  where active_time like '2019-02-23%' and source='12345'
    
    合并为一条sql
    
    SELECT
    
    sum(case when create_time like '2019-02-23%' then 1 else 0 end) as inst_count,
    
    sum(case when active_time like '2019-02-23%' then 1 else 0 end) as active_count
    
    FROM  origin_crx_data   where source='12345'

    原文链接:https://blog.csdn.net/weixin_35952362/article/details/113127237

  • 相关阅读:
    Python循环语句
    Python判断语句
    MySQL的基本操作汇总
    Python函数、类
    Python字典、集合
    Python列表、元组
    python数据类型--数字、字符串
    Python基础认识
    搭建Python独立虚拟环境
    Python包管理工具
  • 原文地址:https://www.cnblogs.com/chong-zuo3322/p/15723024.html
Copyright © 2020-2023  润新知