select case when t4.tattachment_downid IS null then '未下载' else '已下载' end as ftype,
       count(distinct t2.tenterprise_userid)                             as fcount
from tarchives_ad t1
         inner join tenterprise_users t2 on t1.siteid = t2.siteid and t2.fphonenumber is not null
    and t1.fsalercanread = 1 and t2.fusertype = '企业'
         inner join tattachment t3
                    on t1.siteid = t3.siteid and t3.ownertable = 'tarchives_ad' and t3.ownerid = t1.tarchives_adid
         left join tattachment_downlog t4 on t3.siteid = t4.siteid and t3.tattachmentid = t4.tattachmentid and
                                             t2.tenterprise_userid = t4.tenterprise_userid
where t1.siteid = $siteid$ and t1.tarchives_adid=$tarchives_adid$
group by case when t4.tattachment_downid IS null then '未下载'
else'已下载'end