21.查询男生、女生人数
select f.c,m.c
from
(
select count(sid) c from student where ssex='男'
) f
join
(
select count(sid) c from student where ssex='女'
select sname,ssex,count(1)
from student
group by sname,ssex
select cid c,round(avg(score),1) a from sc group by cid order by a,c desc;
26.查询不及格的课程,并按课程号从大到小排列
select s.sid,s.cid,s.score
from
(
select sid,cid,score,row_number()over(partition by cid order by score desc) rank from sc
) s
select f.c,m.c
from
(
select count(sid) c from student where ssex='男'
) f
join
(
select count(sid) c from student where ssex='女'
) m;
select * from student where sname like '%风%';
select sname,ssex,count(1)
from student
group by sname,ssex
having count(1)>1;
select sname from student where substring(sage,0,4)='1990';
select cid c,round(avg(score),1) a from sc group by cid order by a,c desc;
26.查询不及格的课程,并按课程号从大到小排列
select cid c,score from sc where score<60 order by c desc;
select s.sid,s.cid,s.score
from
(
select sid,cid,score,row_number()over(partition by cid order by score desc) rank from sc
) s
where s.rank<=2;
select cid,count(sid) c from sc group by cid having count(sid)>5 order by c desc,cid;
select sid,count(cid) c from sc group by sid having c>=2;
30.查询选修了全部课程的学生信息
select student.sid,student.sname
from
student
join
(
select s.sid
from
(
select count(cid) c from course
) cou
join
(
select sid,count(cid) c from sc group by sid
) s
on cou.c=s.c
) o
on student.sid=o.sid;