首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

找到班级里面男同学和女同学数量相同的班级

2012-08-03 
找出班级里面男同学和女同学数量相同的班级select male.cid, female.cidfrom (select t1.class_id cid, co

找出班级里面男同学和女同学数量相同的班级

select male.cid, female.cid  from (select t1.class_id cid, count(1) total          from t_class t1         where t1.sex = 'male'         group by t1.class_id) male,       (select t2.class_id cid, count(1) total          from t_class t2         where t2.sex = 'female'         group by t2.class_id) female where male.total = female.total   and male.cid = female.cid;

两种写法  两种思路  但是第二种的写法会存在问题  考虑不全面  记下先 

热点排行