【发布时间】:2021-09-15 19:10:11
【问题描述】:
我在使用 laravel eloquent join 来比较 where 子句中的日期时遇到问题。下面的查询给了我错误未知列policy_periods.statecode 我在连接子查询的 where 子句中使用此列,例如 App\Elrd::where("state_code",'=',DB::raw (policy_periods.statecode))->where('date',"max('date')
如果可能有任何解决方案,您能给我一个想法吗? 我已经尝试过 whereRaw,whereColumn 但它们都不起作用。
DB::table('policy_periods')
->join('payrolls','payrolls.policy_period_id', '=', 'policy_periods.id')
->leftjoin('elrds', function($join) use($mod_rating_eff_date)
{
$join->on('elrds.state_code', '=', 'policy_periods.statecode');
$join->on('elrds.class_code', '=', 'payrolls.code');
$join->where('elrds.date',App\Elrd::where("state_code",'=',DB::raw(`policy_periods`.`statecode`))->where('date',"<=",$mod_rating_eff_date)->max('date'));
})
->select('payrolls.*','payrolls.elr as payrollelr','policy_periods.id as pid','policy_periods.policy_no',DB::raw('CONCAT(eff_date, "-", exp_date) as dateGroup'),'policy_periods.eff_date','policy_periods.exp_date','policy_periods.statecode as ratingeffPolicyYear','policy_periods.statecode','elrds.class_code','elrds.year','elrds.date','elrds.elr','elrds.dratio')
->where('policy_periods.mod_id',$id)
->get();
【问题讨论】: