SQL查询语句(男生比女生多的班级)

student(classid int,name varchar(20),sex char(1))查询男生比女人多的班级
2024-12-04 19:42:18
推荐回答(4个)
回答(1):

以1代表'男'和2代表'女', 来代替字段sex的值,

我做的比较啰嗦 不过结果出来了,以下仅供参考:

select aaa.classid from (select classid,count(*) as shu from student where sex='1' group by classid) as aaa,(select classid,count(*) as shu from student where sex='2' group by classid) as bbb where aaa.shu >bbb.shu and aaa.classid=bbb.classid

回答(2):

用select语句查询

select sum(年龄),班级,性别 from Table1 where 班级='A' or 班级='B' group by 班级,性别

回答(3):

select sum(年龄),班级,性别 from Table1 where 班级='A' or 班级='B' group by 班级,性别

回答(4):

select classid
from student
where (select count(sex) from student where sex ='男') > (select count(sex) from student where sex ='女')