`
andey007518
  • 浏览: 21813 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

oracle经典sql面试

 
阅读更多
  一个学校表,school,列class 班级,name  学生姓名,sex 性别,男为'M',女为'F',一个学校表很多的班级,查询出男生,女生数量相同的班级。

好久不搞sql,几乎都忘光了,特此纪念,

select tem.class from(  
select class,  
       (select count(sex)  
          from schools s1  
         where s1.class = s.class  
           and s1.sex = 'M') AS MCOUNT,  
       (select count(sex)  
          from schools s1  
         where s1.class = s.class  
           and s1.sex = 'F') AS FCOUNT  
  from schools s  
group by class  
) tem where tem.MCOUNT = tem.FCOUNT 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics