我想按多個 whereCount 結果的總和排序。這是我的 whereCount
$q->withCount(['ordered', 'favorites']);
我想總結這些ordered_count favorites_count并按這個結果排序。我不太擅長使用 SQL,所以我需要一些幫助。如果使用 eloquent 查詢構建器可以做到這一點,那就更好了。謝謝。
uj5u.com熱心網友回復:
您可以使用orderByRaw按總和排序:
$q->withCount(['ordered', 'favorites'])
->orderByRaw('(ordered_count favorites_count) desc')
->get();
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/363694.html
