|
--select id=1, name='ab', age=20 into #t1
--insert into #t1 select 2, 'cd', 21
--select id=1, course=1, level=1 into #t2
--insert into #t2 select 1, 1, 2
--insert into #t2 select 1, 2, 3
--insert into #t2 select 2, 1, 1
--insert into #t2 select 2, 3, 1
--select * from #t1
--select * from #t2
select t1.*, num=(select count(*) from #t2 t2 where t2.course=1 and t2.id=t1.id)
from #t1 t1
select t1.*, num=count(*)
from #t1 t1, #t2 t2
where t2.id=t1.id
and t2.course=1
group by t1.id, t1.name, t1.age

- 这是一篇来自百度知道的问题
|