[英]How to perform a groupBy in Laravel 5.8?
I have a table with 41 rows 我有一张41行的桌子
I did 我做了
public function types()
{
return DB::table('graphs')->groupBy('title')->get();
}
I kept getting 我不断
Can someone please help ? 有人可以帮忙吗?
I expected to get these 3 我期望得到这3
['MBN_PRIVATE','MBN_GUEST','SPWIFI'];
In MySql strict mode, you can't return non aggregated fields in a group by
query. 在MySql严格模式下,您不能
group by
查询返回组中的非聚合字段。 If you need only the title's values add a select or a pluck method 如果仅需要标题的值,请添加选择或采摘方法
public function types()
{
return DB::table('graphs')->groupBy('title')->pluck('title')->toArray();
}
Try orderBy() instead of groupBy(). 尝试使用orderBy()而不是groupBy()。
public function types()
{
return DB::table('graphs')->orderBy('title')->get();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.