【发布时间】:2020-05-08 09:38:04
【问题描述】:
我想使用 Laravel 查询生成器执行以下 SQL 查询:
select `source`, `customer_id`, COUNT(id) from `requests` where `source` = "ATC" and `customer_id` = 1234567
我尝试了以下代码,但它不能正常工作:
DB::table('requests')->select('source', 'customer_id', DB::raw('COUNT(id)'))->where('source', '=', 'ATC')->where('customer_id', '=', '1234567')->get();
我收到以下错误:
SQLSTATE[42000]: Syntax error or access violation: 1140 In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'opadidb.requests.source'; this is incompatible with sql_mode=only_full_group_by (SQL: select `source`, `customer_id`, COUNT(id) from `requests` where `source` = ATC and `customer_id` = 1234567)
可以帮忙吗?
【问题讨论】: