日期:2014-05-18 浏览次数:20561 次
select a.id,a.gsmc,count(b.companyId) gsum from company a left join gongying b on a.id=b.companyId group by a.id,a.gsmc
------解决方案--------------------
Create table #company ( id int identity(1,1), gsmc nvarchar(50) ) create table #gongying ( id int identity(1,1), companyId int ) insert #company select 'A' union all select 'B' union all select 'C' union all select 'D' insert #gongying select 2 union all select 2 union all select 4 union all select 1 select a.id,a.gsmc,count(b.companyId) gsum from #company a left join #gongying b on a.id=b.companyId group by a.id,a.gsmc drop table #company,#gongying --1 A 1 --2 B 2 --3 C 0 --4 D 1