日期:2014-05-17  浏览次数:20893 次

当没有用 EXISTS 引入子查询时,在选择列表中只能指定一个表达式。
select aIdCodeName, COUNT(companyName) as companyName,
(select aIdCodeName,COUNT (companyName)from dbo.GreenFood where jNYQYJWCTX=0 group by aIdCodeName ) as weikaigonggeshu ,
SUM(zTz) as zTz,SUM(bNDTZ) as bNDTZ,
SUM(jNYQYJWCTX) as jNYQYJWCTX,SUM(xXSR) as xXSR,SUM(liRun) as liRun,SUM(sJ) as sJ from dbo.GreenFood 
  
group by aIdCodeName


------解决方案--------------------
select aIdCodeName, COUNT(companyName) as companyName,
sum(case when jNYQYJWCTX=0 then 1 else 0 end)as weikaigonggeshu ,
SUM(zTz) as zTz,SUM(bNDTZ) as bNDTZ,
SUM(jNYQYJWCTX) as jNYQYJWCTX,SUM(xXSR) as xXSR,SUM(liRun) as liRun,SUM(sJ) as sJ from dbo.GreenFood
 
group by aIdCodeName