需要求出一个班级里 男生 成绩 的总和大于150的班级,降序排列~
不知道这个一个班级里男生成绩的总和怎么算
各位SQL高手帮下哦~~
http://img.photo.163.com/0pg04axkY9WDBgGFUT_Avg==/593067775929622471.jpg
数据库图片~~

解决方案 »

  1.   

    select class from 表 where sex='男' group by class having(sum(score))>150 order by sum(score) desc
      

  2.   

    create table tb(no int,score int,sex char(2),class int)
    insert into tb values(1,100,'男',1)
    insert into tb values(2,50 ,'男',1)
    insert into tb values(3,56 ,'女',1)
    insert into tb values(4,90 ,'男',2)
    insert into tb values(5,61 ,'男',2)
    insert into tb values(6,70 ,'男',3)
    insert into tb values(7,97 ,'男',3)
    goselect class,sum(score) score from tb where sex = '男' 
    group by class having sum(score) > 150
    order by score descdrop table tb/*
    class       score       
    ----------- ----------- 
    3           167
    2           151(所影响的行数为 2 行)
    */