我想按多个whereCount结果的和排序。这是我的whereCount
$q->withCount(['ordered', 'favorites']);我想对这些ordered_count+favorites_count求和,并按此结果排序。我不太擅长使用SQL,所以我需要一些帮助。如果这是可能的,使用雄辩的查询构建器,甚至是better.Thank你。
发布于 2021-11-22 16:56:31
您可以使用orderByRaw按和排序:
$q->withCount(['ordered', 'favorites'])
->orderByRaw('(ordered_count + favorites_count) desc')
->get();https://stackoverflow.com/questions/70068683
复制相似问题