select dt, coalesce(sum(sale_rate),0.000) as sale_rate, coalesce(sum(unsale_rate),1.000) as unsale_rate from ( select dt_group as dt, shop_id, round(count(distinct if(shop_id='901', t1.product_id, null)) / if(shop_id='901',t1.ccnntt,null),3) as sale_rate, round(1-count(distinct if(shop_...