Laravel Eloquent
对于. _ select
_ MySQL
我的查询是这样的。
SELECT
*,
GROUP_CONCAT(p.facility) AS facility
FROM
(SELECT
`proposals`.*,
`proposals`.`desc` AS `pending`,
`proposals`.`Date` AS `date`,
`pl`.`type` AS `facility`,
`ps`.`id` AS `proposalStatusId`,
`ps`.`status` AS `proposalStatus`
FROM
`proposals`
INNER JOIN
(SELECT
*
FROM
(SELECT
*
FROM
`proposal_status`
ORDER BY `created_at` DESC) AS ps
GROUP BY `ps`.`proposalId`
HAVING ps.status BETWEEN 4.2
AND 4.3) AS ps
ON `proposals`.`id` = `ps`.`proposalId`
INNER JOIN `proposal_long` AS `pl`
ON `proposals`.`id` = `pl`.`proposalId`
WHERE `proposals`.`desc` <> ''
HAVING `proposals`.`status` = 1) AS p
DB::select()
当我使用 in并输出所需的结果时,此查询工作正常。但是当实现如下的雄辩关系时不起作用。
$proposals = Proposals::having('status', DMS::PUBLISH);
$proposalsStatusRaw = proposalStatus::orderBy('created_at', 'desc');
$proposalsStatus = DB::table(DB::raw('(' . $proposalsStatusRaw->toSql() . ') AS ps'))
->groupBy('ps.proposalId')
->havingRaw('ps.status between ' . DMS::STEP_5 . ' and ' . DMS::STEP_6);
$proposalsRaw = $proposals->select('proposals.*', 'proposals.desc as pending', 'proposals.Date as date', 'pl.type AS facility', 'ps.id AS proposalStatusId', 'ps.status AS proposalStatus')
->join(DB::raw('(' . $proposalsStatus->toSql() . ') AS ps'), function ($query) {
$query->on('proposals.id', '=', 'ps.proposalId');
})
->join('proposal_long AS pl', function ($query) {
$query->on('proposals.id', '=', 'pl.proposalId');
})
->where('proposals.desc', '<>', '');
$proposals = DB::table(DB::raw('(' . $proposalsRaw->toSql() . ') AS p'))
->select('p.*', DB::raw('GROUP_CONCAT(p.facility) AS facility'));
此关系输出与前面提到的相同的查询,但结果为空值。请帮我解决这个错误。