sql统计各科不及格的人数,要求查询结果是一行

1.score表结构如下:

idusernamechinamathenglish
1zhangsan457798
2lisi465467
3wangwu746323

2.查询各科不及格人数,要求查询结果如下:2.score表结构如下:

chinamathenglish
121

3.sql如下几种方式参考:欢迎吐槽,如您有更好更简洁的写法请提供
     1. select
              sum(china) 'china',
              sum(math) 'math',
              sum(english) 'english'
         from
               (
                       select
                                 count((case  when china<60 then 'china' end)) 'china',
                                 count((case when math<60 then 'math' end)) 'math',
                                 count((case when english<60 then 'english'end)) 'english'
                       from score
                       group by case
                       when china<60 then 'china' when math<60  then 'math' when english<60 then 'english' end)
          t;
     2.select
               (select count(*) from score where china<60) 'china',
               (select count(*) from score where math<60) 'math',
               (select count(*) from score where english<60) 'english'
        from score where china<60 or math<60 or english<60 limit 1;
      3.select
               sum((case china when 'china' then num else 0 end)) 'china',
               sum((case china when 'math' then num else 0 end)) 'math',
               sum((case china when 'english' then num  else 0 end)) 'english'
         from
                 (
                        select 'china',count(*) 'num' from score where china<60
                        union all
                        select 'math',count(*) 'num' from score where math<60
                        union all
                        select 'english',count(*) 'num' from score where english<60
                  ) t;

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值