日期:2014-05-17 浏览次数:20605 次
select a.班级,a.注册人数,isnull(b.cnt,0) as 实际人数
from A
left join (select 班级,count(*) as cnt from B group by 班级) as b
on a.班级=b.班级
SELECT
a.班级,
a.注册人数,
实际人数 = COUNT(B.班级)
FROM tbA a
LEFT JOIN tbB b
ON a.班级 = b.班级
GROUP BY a.班级, a.注册人数