2 回答
TA贡献1827条经验 获得超9个赞
这是由Tray2在Laracasts 上回答的:
确认以下解决方案有效:
$data = DB::select('SELECT provider_id
, o.shortName
, count(b.site_id) as sites
, ( select b.depositFee
+ ( select sum(depositFee)
from backhaul
where backhaul.parent_id=b.id
)
) as entranceFee
, ( select b.rightOfWayCharges
+ ( select sum(rightOfWayCharges)
from backhaul
where backhaul.parent_id = b.id
)
) as rowFee
FROM backhaul AS b
JOIN organisation AS o
ON (b.provider_id = o.id)
WHERE isnull(b.parent_id)
GROUP
BY provider_id
, entranceFee
, rowFee');
TA贡献1876条经验 获得超7个赞
Laravel 很可能将那些用反引号包裹起来,这会导致 MySQL 相信它们是某个表中的实际列。也尝试将它们包裹起来DB::raw。
$data = DB::table("backhaul as b")->select($sql)
->join("organisation as o", "b.provider_id", "=", "o.id")
->whereNull("b.parent_id")
->groupBy([
"b.provider_id",
\DB::raw('entranceFee'),
\DB::raw('rowFee'),
])
->paginate() ;
- 2 回答
- 0 关注
- 151 浏览
添加回答
举报