select * from tb_student(学生表) stu left join score sco on stu.id=sco.stu_id
右连接
select * from tb_student(学生表) stu right join score sco on stu.id=sco.stu_id
[SNO] 学号,[SEX] 性别
,[Grade] 班级
select Grade as 班级,convert(decimal(18,2),sum(case when sex='男' then 1 else 0 end )*1.0/count(Sex)*100) as [男生比例],convert(decimal(18,2),sum(case when sex='女' then 1 else 0 end )*1.0/count(Sex)*100) as [女生比例]
from [student]
group by Grade
order by convert(decimal(18,2),sum(case when sex='男' then 1 else 0 end )*1.0/count(Sex)*100)
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)