工作,我想算职位#旁边所有类别物品列表如下:Laravel 5.3:选择leftjion不与GROUPBY
- 类别1(25)
- 类别2(12)
- 类别3(8)
- 类别...(67)
在Laravel 5.2,我使用以下代码来实现上述结果:
$cateCount = Category::leftjoin('posts', 'posts.icategoryid', '=', 'categories.id')
->groupBy('categories.id')
->get(['categories.id', 'categories.name', DB::raw('count(posts.icategoryid) as mycount')]);
不过,我升级到Laravel 5.3,这显示出以下错误:
SQLSTATE [42000]:语法错误或访问冲突:1055 'posts.categories.name' 是不是在GROUP BY(SQL:select
categories
。id
,categories
。name
,count(posts.icategoryid)作为mycount从categories
左加入posts
在posts
。icategoryid
=categories
。id
组由categories
。id
)
你能告诉我怎么解决这个问题或任何更好的方法来实现上述结果呢?
感谢,Vannak