Laravel 5具有Raw查询的可能解决方案是什么?

时间:2017-11-23 03:53:33

标签: php mysql laravel

$sql = 'AG.int_partner_key, PA.`tx_partner_name` AS partner_name, rs.*,count(p.park_id) as park_count, p.reason, p.remark,'
        . 'p.created_at as parked_time, su.name as parked_by,'
        . 'su.name AS locked_by';
        $rows = DB::table('raw_subscribers as rs')                                         
        ->join('parks as p','p.raw_subscriber_id','=','rs.raw_subscriber_id')                
        ->join('users as pu','pu.user_id','=','p.user_id')
        ->leftJoin('outreach_partner_agents as AG','AG.tx_agent_id','=','rs.health_worker_id')
        ->leftJoin('outreach_partners as PA','PA.int_outreach_partner_key','=','AG.int_partner_key')
        ->leftJoin('subscriber_locks as sl','sl.raw_subscriber_id','=','rs.raw_subscriber_id')
        ->leftJoin('users as su','su.user_id','=','sl.user_id')
        ->select(DB::raw($sql.' AG.int_partner_key as partner_id'))
        ->where('rs.verification_status','=','PARKED')
        ->whereRaw('p.call_time is NULL');

        $rows = $rows->orderBy(DB::raw("DATE_FORMAT(p.created_at,'%Y-%m-%d')"))
            ->groupBy('rs.raw_subscriber_id')
            ->havingRaw('AG.int_partner_key=14')
            ->orderBy('park_count','DESC')                
            //->toSql();
            ->paginate(50);

错误:未找到列:1054未知列' AG.int_partner_key'在'有条款' (SQL:选择count(*)作为raw_subscribers的聚合 但是,如果我使用toSql()来获取查询并在sql编辑器中运行查询,它的工作正常。我不明白查询的问题是什么。

0 个答案:

没有答案