sql一些实用统计
student(sno,sname,ssex,snative)–snative 是民族
course(cno,cname,credit)
sc(sno,cno,grade)
统计学生来自于哪些民族,每个民族有多少人?
select snative,count(snative) from student group by snative
统计所有有学生修读的课程的学分
select sum(c.credit)
from course c
inner join (select distinct sc.cno from sc) s
on c.cno=s.cno
统计每门课程,每个等级的学生人数
select c.cno,s.grade,count(s.sno)
from course c
inner join sc s
on c.cno=s.cno
group by s.grade,c.cno;