user表:

多个count统计sql语句

        select
        count(case when sex ='男' then 1 end) as man,
        count(case when sex ='女' then 1 end) as woman,
        count(case when age>=18 then 1 end) as adult,
        count(case when age<18 then 1 end) as nonage
        from user

 可根据自己的业务更改when后面的条件

查询结果:

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐