HQDR(提问者) 回复 CD20160914select count(1) as sl,
c3.SHORT_NAME 公司
from MS_CallDetail a with(nolock)
left join MS_Dept c with(nolock) on c.DEPT_ID=a.DEPT_ID
left join (select distinct DEPT_ID,left(DEPT_CODE, 5) as DEPT_CODE from MS_Dept) c2 on c2.DEPT_ID=a.DEPT_ID
left join (select distinct * from MS_Dept where len(DEPT_CODE) = 5) c3 on c3.DEPT_CODE = c2.DEPT_CODE
where c3.SHORT_NAME is not null
and c3.SHORT_NAME not in (\'冠松二手车\',\'静安日产\',\'南京斯柯达\',\'停用公司\',\'浦东公司\',\'闸北公司\')
and a.COME_TYPE in (2,3)
${if(len(rq) == 0, \"\", \"and left(a.CALL_TIEM,7) = (\'\" + rq + \"\')\") }
${if(len(gs) == 0, \"\", \"and left(c.dept_code,5) in (\'\" + gs + \"\')\") }
group by c3.SHORT_NAME (这个是查当月数据)
select count(1) as sl,
c3.SHORT_NAME 公司
from MS_CallDetail a with(nolock)
left join MS_Dept c with(nolock) on c.DEPT_ID=a.DEPT_ID
left join (select distinct DEPT_ID,left(DEPT_CODE, 5) as DEPT_CODE from MS_Dept) c2 on c2.DEPT_ID=a.DEPT_ID
left join (select distinct * from MS_Dept where len(DEPT_CODE) = 5) c3 on c3.DEPT_CODE = c2.DEPT_CODE
where c3.SHORT_NAME is not null
and c3.SHORT_NAME not in (\'冠松二手车\',\'静安日产\',\'南京斯柯达\',\'停用公司\',\'浦东公司\',\'闸北公司\')
and a.COME_TYPE in (2,3)
and left(a.CALL_TIEM,7) = \'${format(MONTHDELTA(rq,-1),\"yyyy/MM\")}\'
${if(len(gs) == 0, \"\", \"and left(c.dept_code,5) in (\'\" + gs + \"\')\") }
group by c3.SHORT_NAME(这个是查上个月的)