[英]Laravel 5 Column it is not contained in either an aggregate function or the GROUP BY
I got an error in SQL when trying to join and group the id using Laravel. 尝试使用Laravel合并ID并将其分组时,SQL出现错误。
Column 'push_notifications.title' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
选择列表中的“ push_notifications.title”列无效,因为它既不包含在聚合函数中,也不包含在GROUP BY子句中
I've been trying to use Max and Min but I still got an error. 我一直在尝试使用最大和最小,但仍然出现错误。
Here's my code : 这是我的代码:
$data = $this->model->select( 'push_notifications.id', 'push_notifications.title', 'push_notifications.description', 'push_notifications.attachment', 'push_notifications.feature_id', 'push_notifications.target_id', 'features.title as feature', 'push_notifications.end_at')
->join('push_notification_users', 'push_notification_users.push_notification_id', '=', 'push_notifications.id')
->join('push_notification_roles', 'push_notification_roles.push_notification_id', '=', 'push_notifications.id')
->leftJoin('features', 'features.id', '=', 'push_notifications.feature_id')
->where( 'push_notifications.notif_target', 'homepage' )
->where(function($role) {
$roles = RoleUser::where('user_id',$this->user->id)->first();
$role->where( 'push_notification_roles.deleted_at', null )
->where( 'push_notification_roles.role_id', $roles->role_id );
})
->orWhere(function($user) {
$user->where( 'push_notification_users.deleted_at', null )
->where( 'push_notification_users.user_id', $this->user->id );
})
->where( 'push_notifications.end_at', '>', Carbon::now()->toDateTimeString() )
->groupBy( 'push_notifications.id' )
->get();
If you have any solution just tell Me, I will really appreciate. 如果您有任何解决方案,请告诉我,我将不胜感激。 Thank You
谢谢
'push_notifications.title' is not found. 找不到“ push_notifications.title”。 May there be some spelling mistake.
可能有一些拼写错误。 Check thoroughly.
彻底检查。 If not so then please attach screenshot of your table structure ie push_notifications.
如果不是这样,那么请附上表格结构的屏幕快照,即push_notifications。
Also another reason is that there must be diff-diff values of push_notifications.title for 'push_notifications.id' and there can be multiple 'push_notifications.title' for single 'push_notifications.id' in groupBy. 另外一个原因是'push_notifications.id'必须有push_notifications.title的diff-diff值,并且groupBy中的单个'push_notifications.id'可以有多个'push_notifications.title'。 Only select 'push_notifications.id' and some other unique columns will work in your case.
仅选择“ push_notifications.id”,其他一些唯一列将适用于您的情况。
refer this: https://www.techonthenet.com/sql/group_by.php 请参阅此: https : //www.techonthenet.com/sql/group_by.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.