简体   繁体   English

[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

I am using laravel with mssql and getting this error with simple group by query.我正在将 laravel 与 mssql 一起使用,并通过简单的 group by 查询得到这个错误。 RetailersModel::groupBy('state')->get(); RetailersModel::groupBy('state')->get();

And it returns me error.它返回给我错误。 I have migrating database server from mysql to mssql.我已将数据库服务器从 mysql 迁移到 mssql。 Mysql is running fine but error occur when try to get record from ms-sql database server. Mysql 运行良好,但尝试从 ms-sql 数据库服务器获取记录时发生错误。

I have also set strict false in mysql and mssql config in database php.我还在数据库 php 中的 mysql 和 mssql 配置中设置了严格的 false。

Thanks in advance.提前致谢。

RetailersModel::groupBy('state')->get();

尝试执行此查询

  RetailersModel::select('*','state', DB::raw('COUNT(state) as state'))->groupBy('state')->get();

暂无
暂无

声明:本站的技术帖子网页,遵循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” Laravel 5列既不包含在聚合函数中,也不包含在GROUP BY中 - Laravel 5 Column it is not contained in either an aggregate function or the GROUP BY 选择列表不在 group by 子句中并且包含非聚合列 laravel - select list is not in group by clause and contains nonaggregated column laravel 检查 id 是否包含在 SQL 和 PHP 的列表中 - Check if an id is contained in a list in SQL and PHP SELECT列表不在GROUP BY子句中错误mysql - SELECT list is not in GROUP BY clause ERROR MySQL SQLSTATE [42S22]:未找到列:1054 'where 子句'中的未知列 'id'(SQL:select * 来自 `songs` where `id` = 5 limit 1) - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from `songs` where `id` = 5 limit 1) SELECT 列表的表达式 #1 不在 GROUP BY 子句中并且包含非聚合列。 仅在共享主机 cPanel 中出错 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column. Getting error only in Shared Hosting cPanel SQL从表总和中选择ID并按ID分组 - SQL Select * from table sum and group by id have 子句中的未知聚合列 - Unknown aggregate column in having clause 在没有GROUP BY的聚合查询中,SELECT列表的表达式#2包含非聚合列'abid'; - In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column 'a.b.id';
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM