gpt4 book ai didi

mysql - GROUP_CONCAT 的 Laravel 代码不起作用

转载 作者:行者123 更新时间:2023-11-29 16:12:54 26 4
gpt4 key购买 nike

我想使用 MySQL 在我的 Laravel 项目上创建逗号分隔的结果。我知道我必须使用 GROUP_CONCAT 并且我使用工作台使其在 mysql 上完美工作。但是当我在 Laravel 代码上使用它时出现错误。请检查下面我的实际代码。当我删除 GROUP_CONCAT 行/部分时,我的代码可以完美运行。

我调用 API 时的错误代码是:500(内部服务器错误)

 $result = Rmim\WhQcHdr::from('wh_qc_hdrs as hdr')->select(
'rr.TrxDate as RR Date',
'hdr.rr_no as RR No',
'hdr.inspected_at as Date of Inspection',
'hdr.qcir_no as QCIR No',
'hdr.item_code as Item Code',
'item.ItemDesc as Item Description',
'hdr.supplier_code as Supplier Code',
'con.ContactName as Supplier Name',
'hdr.reject_reason as Reason of Rejection',
'hdr.cancel_reason as Reason of Cancellation',
\DB::raw('(CASE WHEN hdr.qc_status="A" THEN "Passed"
WHEN hdr.qc_status="CA" THEN "Conditionally Approved"
WHEN hdr.qc_status="R" THEN "Rejected"
WHEN hdr.qc_status="C" THEN "Cancelled"
ELSE "N/A"
END) as Disposition'),

-- line below causes an error when I call my api, it works perfectly if I remove it.
\DB::raw('GROUP_CONCAT(dtl.parameters) as Failed Parameters')
)

->leftJoin('rminv.tbl_rmtrninv as rr', function ($join){
$join->on('hdr.rr_no', '=','rr.trxnum')
->where('rr.TransID', '=', 2);
})
->leftJoin('rminv.tbl_rmmstitem as item', 'hdr.item_code', '=', 'item.ItemCode')
->leftJoin('fginv.tbl_fgmstcontacts as con','hdr.supplier_code','=','con.ContactCode')
->leftJoin('crp.wh_qc_dtls as dtl', function ($join){
$join->on('hdr.id', '=','dtl.qc_id')
->where('dtl.result', '=', 0);
})
->groupBy('rr.TrxDate',
'hdr.rr_no',
'hdr.inspected_at',
'hdr.qcir_no',
'hdr.item_code',
'item.ItemDesc',
'hdr.supplier_code',
'con.ContactName',
'hdr.reject_reason',
'hdr.cancel_reason',
\DB::raw('(CASE WHEN hdr.qc_status="A" THEN "Passed"
WHEN hdr.qc_status="CA" THEN "Conditionally Approved"
WHEN hdr.qc_status="R" THEN "Rejected"
WHEN hdr.qc_status="C" THEN "Cancelled"
ELSE "N/A"
END)'))
->orderBy('hdr.created_at', 'Desc');

提前谢谢您。

最佳答案

我刚刚将别名从 FailedParameters 变为 Failed_Parameters 的 1 个单词,错误就消失了。我真的不知道为什么,因为在其他字段中超过 1 个单词的别名没问题,但在 GROUP_CONCAT 部分会出错。

如果有人能够解释这一点,请这样做,这将是一个很大的帮助。

关于mysql - GROUP_CONCAT 的 Laravel 代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55095147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com