班级与性别对应表
classId
sex要求写出查询男女相等的班级的SQLclassId sex
1 男
1 女
1 男
1 女
2 男
2 女
2 男
3 男
3 女
3 女
4 男
4 女
帮帮小弟吧
classId
sex要求写出查询男女相等的班级的SQLclassId sex
1 男
1 女
1 男
1 女
2 男
2 女
2 男
3 男
3 女
3 女
4 男
4 女
帮帮小弟吧
就是classId Int(10),
sex varchar(50),
不知道哪有有错,请老大们帮忙说说!
from (select classId,count(*) as cnt from 表结构 where sex='男' group by classId) a
, (select classId,count(*) as cnt from 表结构 where sex='女' group by classId) b
where a.classId=b.classId and a.cnt=b.cnt
SELECT classId FROM TTH
GROUP BY classId HAVING SUM(IF(sex='男',1,0))=SUM(IF(sex='女',1,0))