select left(Z.状态时间, 6) 月份, U.用户名 操作员, U.组名, Z.手别, 
       sum(case when Z.案件状态 = '在案' then 1 else 0 end) 在案户数, 
       sum(case when Z.案件状态 = '在案' then Z.欠款余额 else 0 end) 在案金额, 
       sum(case when Z.案件状态 = '退案' then 1 else 0 end) 退案户数, 
       sum(case when Z.案件状态 = '退案' then z.欠款余额 else 0 end) 退案金额,
       sum(case when Z.案件状态 = '结案' then 1 else 0 end) 结案户数, H.回款数
  from 案件状态表 Z
  left join 还款表 H on Z.外包序号 = H.外包序号
  left join 用户表 U on Z.操作员 = U.用户名
 group by
  left(Z.状态时间, 6) 月份, U.用户名 操作员, U.组名, Z.手别, H.回款数