SELECT count(*) as count_num, stat_type
  FROM (select (case
                 when (APPLY_AREA_CODE is not null) and
                      length(APPLY_AREA_CODE) >= 4 and
                      (substr(APPLY_AREA_CODE, 3, 2) <> '00' or
                      substr(APPLY_AREA_CODE, 1, 2) = '12' or
                      substr(APPLY_AREA_CODE, 1, 2) = '11' or
                      substr(APPLY_AREA_CODE, 1, 2) = '31' or
                      substr(APPLY_AREA_CODE, 1, 2) = '51') then
                  USER_ADDRESS3
                 else
                  USER_ADDRESS2
               end) stat_type
        
          from tmp_ar_statisticinfo
        
         where (STATION_STAT_STATUS = '1' and APPLY_APP_SUBJECT = '1')
              
            or (STATION_STAT_STATUS = '1' and APPLY_APP_SUBJECT = '0' and
               USER_USER_TYPE = '0')) group by stat_type;