1. 程式人生 > >mysql去掉重複資料

mysql去掉重複資料

 $subOrderActionQuery = M('action_position')
            ->field('org_parent_id,shop_id,saleman_id,today,datediff(\'' . $nowDate . '\',' . 'today) as noto')
            ->where('org_parent_id = ' . $org_parent_id . ' and shop_id != 0')
            ->order('today desc')
            ->select(false);
    $subActionQuery = M()
    ->table($subOrderActionQuery . ' temp')
    ->group('shop_id')
    ->where('org_parent_id = ' . $org_parent_id)
    ->select(false);
     
    $data = M('customer_info as ci')
    ->distinct(true)
    ->field('ci.cust_id,ci.cust_code,ci.cust_name,concat(ci.province,ci.city,ci.district,ci.address) as addr,ap.today,ap.noto,ci.create_time,ap.saleman_id')     
    ->join('left join ' . $subActionQuery . ' as ap ON  ap.org_parent_id = ci.org_parent_id and ap.shop_id = ci.cust_id')    
    ->where('ci.org_parent_id='.$org_parent_id.' and ci.is_close=0 '.$where)
    ->group('ci.cust_id')
    ->order('ap.noto asc')
    ->select();