SQL查询语句(男生比女生多的班级)
来源:百度知道 编辑:UC知道 时间:2024/05/29 14:34:03
student
(
classid int,
name varchar(20),
sex char(1)
)
查询男生比女人多的班级
(
classid int,
name varchar(20),
sex char(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
用select语句查询
select sum(年龄),班级,性别 from Table1 where 班级='A' or 班级='B' group by 班级,性别
select sum(年龄),班级,性别 from Table1 where 班级='A' or 班级='B' group by 班级,性别
select classid
from student
where (select count(sex) from student where sex ='男') > (select count(sex) from student where sex ='女')