美文网首页
PostgresSQL将多条子查询的统计结果作为查询结果

PostgresSQL将多条子查询的统计结果作为查询结果

作者: 李北北 | 来源:发表于2019-01-15 09:33 被阅读0次
    SELECT
    
        (SELECT COUNT (*) FROM d_info WHERE type = 0) AS common_total_count, --0普通总数
    
        (SELECT COUNT (*) FROM d_info WHERE type = 0 AND status = 0) AS common_offline_count, -- 00普通离线数量
    
        (SELECT COUNT (*) FROM d_info WHERE type = 0 AND status = 1) AS common_online_count, -- 01普通在线数量
    
        (SELECT COUNT (*) FROM d_info WHERE type = 1) AS special_total_count, --特殊总数量
    
        (SELECT COUNT (*) FROM d_info WHERE type = 1 AND status = 0) AS special_offline_count, -- 10特殊离线数量
    
        (SELECT COUNT (*) FROM d_info WHERE type = 1 AND status = 1) AS special_online_count; -- 11特殊在线数量
    

    相关文章

      网友评论

          本文标题:PostgresSQL将多条子查询的统计结果作为查询结果

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