我在运行此代码时遇到问题。上面写着:
语法错误或访问冲突:1064您的SQL中有错误语法。
我不知道这是否来自subquery
。这样写subquery
正确吗?
$result = DB::table('grievance_redress_info')
->select(
'complainer_name',
'phone',
'complaint_date',
'address',
'complaintSub.name_en',
'resolve_action_date',
DB::raw("(SELECT grievance_history.status
FROM grievance_history
WHERE grievance_history.grievance_id=grievance_redress_info.id
ORDER BY grievance_history.id DESC LIMIT 1) AS current_status")
)
->leftJoin("common_labels AS
complaintSub",'grievance_redress_info.complaint_subject_id','=','complaintSub.id')
->get();
我想你可以做一些类似的事情
$grievance_redress_info = DB::table('grievance_redress_info')
->select(
'complainer_name',
'phone',
'complaint_date',
'address',
'complaintSub.name_en',
'complaintMeans.name_en',
'resolve_action_date');
$result = DB::table('grievance_history')
->leftJoinSub($grievance_redress_info, 'grievance_redress_info', function ($join) {
$join->on('grievance_history.grievance_id', '=', 'grievance_redress_info.id');
})->select('grievance_history.status')->get();
你可以查看文档了解更多
我希望这能奏效!