and b.hzjxsdm in(select hzjxsdm from gcxxtz with(nolock)where cxbz ='柳汽' and yxbz='1')
==>and exists(select 1 from gcxxtz with(nolock) where cxbz ='柳汽' and yxbz='1' and hzjxsdm=b.hzjxsdm)
==>and exists(select 1 from gcxxtz with(nolock) where cxbz ='柳汽' and yxbz='1' and hzjxsdm=b.hzjxsdm)
isnull(sum(ygje),0) as sumygje,isnull(sum(ysbj),0) as sumysbj,
isnull(sum(yslx),0) as sumyslx from
(select a.khmc,a.hzjxsdm,a.hzjxsmc,a.sf,a.hth,a.ysbj,a.yslx,a.ygje,a.qs,
case when charindex('十堰',kkyh)>0 and (charindex('建设',kkyh)>0 or charindex('建行',kkyh)>0)then
'中国建设银行股份有限公司十堰分行' when isnull(kkyh,'')='' then '统一扣款' else kkyh end kkyh,b.kkyhzh from ht b with(nolock), ysygmx a with(nolock)
where a.yxbz='1' and b.yxbz='1' and a.hth=b.hth and convert(char(6),a.hkrq,112)='200709'
and exists(select 1 from gcxxtz with(nolock) where cxbz ='柳汽' and yxbz='1' and hzjxsdm=b.hzjxsdm)
) a group by hzjxsdm,isnull(kkyh,'')
order by hzjxsdm
需要1分14秒啊!!!