我在使用Laravel Query Builder时遇到了一些麻烦。我想转换此SQL查询:
select (select sum(amount) from transactions t
join sale w on w.id = t.sale_id
join types s on s.id = w.type_id
where s.name = 'Bronze'
) as sum_amount
from transactions
limit 1;
如何在我的laravel查询构建器上实现此查询? 我正在使用laravel 5.2
希望有人帮助我:)谢谢
答案 0 :(得分:0)
你可以试试这个:
DB::table('transactions')
->select(DB::raw("(select sum(amount) from transactions t
join sale w on w.id = t.sale_id
join types s on s.id = w.type_id
where s.name = 'Bronze'
) as sum_amount"))
->take(1)
->get();
希望这有帮助