我有一个SQL查询。
SELECT
nguyenlieu.manguyenlieu,
nguyenlieu.tennguyenlieu,
SUM(chitietnhapmua.soluong) AS slsum
FROM chitietnhapmua
JOIN nguyenlieu
ON nguyenlieu.manguyenlieu = chitietnhapmua.manguyenlieu
JOIN
(SELECT nhapmua.* FROM nhapmua WHERE nhapmua.trangthai = 1) AS nhapmua
ON nhapmua.maphieunhap = chitietnhapmua.maphieunhap
GROUP BY nguyenlieu.manguyenlieu
它在SQL上运行。我得试试
$data = DB::table('nguyenlieu')
->join('chitietnhapmua','nguyenlieu.manguyenlieu','=','chitietnhapmua.manguyenlieu')
->join('nhapmua',function($join){
$join->on('nhapmua.maphieu','=','chitietnhapmua.maphieu')
->where('nhapmua.trangthai','=','1');
})
->select('nhapmua.maphieunhap','nguyenlieu.manguyenlieu','nguyenlieu.tennguyenlieu','chitietnhapmua.soluong')
->get();
但我无法使用类DB转换为Laravel框架。