我正在使用laravel 4并拥有像这样的SQL查询
select a.*, v.* from (select * from application order by id desc)a join vacancy v on a.vacancy_id = v.id group by a.email
我的问题是如何在查询构建器中编写
答案 0 :(得分:0)
您可以尝试这样的事情。 (另)
$subQuery = DB::table('application')->orderBy('id', 'desc');
$result = DB::table(\DB::raw("({$subQuery->toSql()}) as a"))
->mergeBindings($subQuery)
->selectRaw("a.*, v.*")
->join('vacancy as v', 'a.vancancy_id', 'v.id')
->groupBy('a.email')
->get();