如何使用laravel进行查询,类似下面的示例谢谢
with s as (select s.id from s) select a.* from a left join s on s.id = a.s_id ...
ddrv8njm1#
Eloquent不支持WITH子句。您可以传入原始查询
$sql = <<<SQL with s as (select s.id from s) select a.* from a left join s on s.id = a.s_id ... SQL; $results = DB::select($sql);
或者使用添加了此功能的软件包,如staudenmeir/laravel-cte
staudenmeir/laravel-cte
DB::query() ->withExpression('s', fn ($query) => $query->select('s.id')->from('s')) ->select('a.*') ->from('a') ->leftJoin('s', 's.id', 'a.s_id') ...
1条答案
按热度按时间ddrv8njm1#
Eloquent不支持WITH子句。您可以传入原始查询
或者使用添加了此功能的软件包,如
staudenmeir/laravel-cte