落叶的追求 2015-12-01 01:19 采纳率: 100%
浏览 1905
已采纳

mysql分段数据统计sql怎么写

图片说明
1.
这是一张班级的成绩表,想统计出每个成绩段的数据,mysql的sql语句该怎么写呢。
图片说明

  • 写回答

2条回答 默认 最新

  • GrowingDarker 2015-12-01 02:44
    关注
    
    select '60分以下' type, count(*) from student s where  s.score < 60
         union all 
         select '60分以上70分以下' type,count(*) from student s where  s.score < 70 and s.score > 60
            union all
          select '70分以上80分以下' type,count(*) from student s where  s.score < 80 and s.score > 70
        union all
          select '80分以上90分以下' type,count(*) from student s where  s.score < 90 and s.score > 80
       union all
          select '90分以上' type,count(*) from student s where s.score > 90;
    
                结果
                +------------------+----------+
    | type             | count(*) |
    +------------------+----------+
    | 60分以下         |        1 |
    | 60分以上70分以下 |        1 |
    | 70分以上80分以下 |        2 |
    | 80分以上90分以下 |        1 |
    | 90分以上         |        3 |
    +------------------+----------+
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?