简体   繁体   English

Laravel 5列既不包含在聚合函数中,也不包含在GROUP BY中

[英]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.

相关问题 该列“在选择列表中无效,因为它既不在聚合函数中也不在GROUP BY子句中” - Column is “invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause” [SQL Server]列“retailers.id”在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中 - [SQL Server]Column 'retailers.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause SqlClient.SqlException:找不到列“ dbo”或用户定义的函数或聚合“ dbo.fn_rt_getlevel”,或者名称不明确 - SqlClient.SqlException: Cannot find either column “dbo” or the user-defined function or aggregate “dbo.fn_rt_getlevel”, or the name is ambiguous 按汇总函数排序Laravel雄辩 - Order By Aggregate Function Laravel Eloquent Laravel上的Elasticsearch聚合函数错误 - Elasticsearch aggregate function error on laravel Laravel Group按关系栏目 - Laravel Group By relationship column 在Mysql中获取分组后的列的聚合计数 - Get Aggregate Count of Column After Group by in Mysql 使用鞋垫功能检查任一列是否为空 - Check if either column is null using insole function 在 Jessengers MongoDB 中使用 Laravel Lumen 中的聚合函数 - use of aggregate function in Laravel Lumen with Jessengers MongoDB 按多列分组收集-Laravel - Group Collection by multiple column - Laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM