select
class.cgrade,
class.code,
class.cname,
count(stu.sid) as 人数
from
class JOIN stu
ON (class.cid = stu.scid)
group by
class.cgrade,
class.code,
class.cname
order by
count(stu.sid) desc
GO
cgrade code cname 人数
------------------------------- -----------
一年级 c002 2 2
一年级 c001 1 1
(2 行受影响)
select c.cname,count(s.sId) as Num from
stu s,class c
where s.scid=c.cid
group by c.cname
order by Num
select cgrade ,count(*) as 人数 from stu,class
where stu.cid=class.cid
group by cgrade
order by count(*) desc