在Laravel中按多列分组 [英] Group by multiple columns in Laravel
本文介绍了在Laravel中按多列分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何 GROUP BY
Laravel中的多列?
我试过这个代码:
How to GROUP BY
multiple column in Laravel?
I tried this code:
$routes = DB::table('route')
->groupBy('rte_origin')
->groupBy('rte_destination')
->get();
但这不起作用。
推荐答案
您尝试过:
$routes = DB::table('route')
->groupBy('rte_origin', 'rte_destination')
->get();
现在无法测试,但API说groupBy()接受数组。
Can't test here right now, but the API says groupBy() accepts an array.
请参阅:
- Laravel 5.0: https://github.com/laravel/framework/blob /5.0/src/Illuminate/Database/Query/Builder.php#L1037
- Laravel 4.2: https://github.com/laravel/framework/blob/4.2/src/Illuminate/Database/Query/Builder .php#L1017
- Laravel 5.0: https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Query/Builder.php#L1037
- Laravel 4.2: https://github.com/laravel/framework/blob/4.2/src/Illuminate/Database/Query/Builder.php#L1017
这篇关于在Laravel中按多列分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文