[英]PHP & Laravel | Use OrderBy after a GroupBy
This is my Php code这是我的 Php 代码
$elements= DB::table('transactions')
->select('product_id', DB::raw('count(*) as total'))
->groupBy('product_id')
->get();
I want to apply an orderby and a limit('5') on count
我想在
count
上应用 orderby 和 limit('5')
Any orientation?有什么方向吗? Thank you.
谢谢你。
add orderBy()..and take()添加 orderBy().. 和 take()
$elements= DB::table('transactions')
->select('product_id', DB::raw('count(*) as total'))
->groupBy('product_id')
->orderBy('your_column')
->take(5)
->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.