select  case when t3.tattachment_downid IS null then '未下载'else'已下载'end as ftype,count(distinct t1.tenterprise_userid)as fcount
from tenterprise_users t1
       inner join tattachment t2 on t1.siteid=t2.siteid and t2.ownertable='tarchives' and t2.ownerid=$tarchivesid$
       left join tattachment_downlog t3 on t2.siteid=t3.siteid and t2.tattachmentid=t3.tattachmentid and t1.tenterprise_userid=t3.tenterprise_userid
    inner join tagents t4 on t1.siteid=t4.siteid and t1.tagentsid=t4.tagentsid
where t1.siteid = $siteid$ and t1.fisadministrator=1 and t1.fusertype = '经销商' and t4.fsaleruserid in $tenterprise_userid$
group by case when t3.tattachment_downid IS null then '未下载'else'已下载'end